I would like my macro to run x number of times.
This x value is stored in a table value. [Tables]![Panels_Total]![Total Panels]So if the value in the column Total Panels is 26, the macro would run 26 times.
Afa
I would like my macro to run x number of times.
This x value is stored in a table value. [Tables]![Panels_Total]![Total Panels]So if the value in the column Total Panels is 26, the macro would run 26 times.
Afa
This may help retrieve the value from my table..
Code:Function GetGST() As String Dim db As Database Dim Lrs As DAO.Recordset Dim LSQL As String Dim LGST As String 'Open connection to current Access database Set db = CurrentDb() 'Create SQL statement to retrieve value from GST table LSQL = "select GST from GST" Set Lrs = db.OpenRecordset(LSQL) 'Retrieve value if data is found If Lrs.EOF = False Then LGST = Lrs("GST") Else LGST = "Not found" End If Lrs.Close Set Lrs = Nothing GetGST = LGST End Function
And I would like to reference this value like this
Code:vNum = LGST DoCmd.RunMacro "Print Sales", vNum
something like this maybe?
To get the GST, try:
If you are using a MACRO, then this would probably work, but there might be issues about timing.Code:Function GetGST() As Integer Dim db As DAO.Database Dim Lrs As DAO.Recordset Dim LSQL As String Dim LGST As String 'Open connection to current Access database Set db = CurrentDb() 'default return value GetGST = 0 'Create SQL statement to retrieve value from GST table LSQL = "SELECT GST FROM GST" '<-- IMHO, it is poor programming practice to use the same name for two or more objects. 'I would use tblGST for the table name Set Lrs = db.OpenRecordset(LSQL) 'Retrieve value if data is found If Lrs.EOF = False Then LGST = Lrs("GST") GetGST = LGST End If Lrs.Close Set Lrs = Nothing Set db = Nothing End Function
Code:vNum = GetGST DoCmd.RunMacro "Print Sales", vNum
If you are using VBA code, then look at this: (issues about timing)
Code:Dim vNum As Integer Dim x As Integer vNum = GetGST If vNum > 0 Then For x = 1 To vNum 'do things 'might need a delay to allow process to finish before the loop starts over Next End If