I was wondering once a Module is created, how does the actual Module work in a Query, so that the Code would run, behind the scenes, automatically when I apply an Update/Refresh Button to a Form.
Please note the original Code written by Remou:
Sub Award()
Dim rs As DAO.Recordset
Dim rsA As DAO.Recordset
strSQL = "SELECT t.CustomerID, Rnd([CustomerID]) AS RandCust, t.AwardID, t.AwardDate " _
& "FROM CustomerAwards t " _
& "WHERE t.AwardID Is Null " _
& "ORDER BY Rnd([CustomerID])"
Set rs = CurrentDb.OpenRecordset(strSQL)
strSQL = "SELECT AwardID FROM Awards"
Set rsA = CurrentDb.OpenRecordset(strSQL)
Do While Not rs.EOF()
rs.Edit
rs!AwardID = rsA!AwardID
rs!AwardDate = Format(Date(),"yyyy/mm/dd")
rs.Update
rs.MoveNext
rsA.MovenextLoopEnd Sub
-------
Now I just need the Code to run behind the scenes when a botton is pressed on a Form to activiate the process of the Module whereas that same data/information will be sent to a Report.
(1) Do I need to create a separate Query for this to happen, if so, how? OR
(2) Do I just add a button to a Form and place a separate Code on the button, if so, how? OR
(3) Do I create a Macro to activate the Module, if so, how?
Thus far, I can only execute the Module by pressing Run in the Module window. I'm sure there is a cleaner way to perform/execute this process. Any suggestions...?
Please note the original Code written by Remou:
Sub Award()
Dim rs As DAO.Recordset
Dim rsA As DAO.Recordset
strSQL = "SELECT t.CustomerID, Rnd([CustomerID]) AS RandCust, t.AwardID, t.AwardDate " _
& "FROM CustomerAwards t " _
& "WHERE t.AwardID Is Null " _
& "ORDER BY Rnd([CustomerID])"
Set rs = CurrentDb.OpenRecordset(strSQL)
strSQL = "SELECT AwardID FROM Awards"
Set rsA = CurrentDb.OpenRecordset(strSQL)
Do While Not rs.EOF()
rs.Edit
rs!AwardID = rsA!AwardID
rs!AwardDate = Format(Date(),"yyyy/mm/dd")
rs.Update
rs.MoveNext
rsA.MovenextLoopEnd Sub
-------
Now I just need the Code to run behind the scenes when a botton is pressed on a Form to activiate the process of the Module whereas that same data/information will be sent to a Report.
(1) Do I need to create a separate Query for this to happen, if so, how? OR
(2) Do I just add a button to a Form and place a separate Code on the button, if so, how? OR
(3) Do I create a Macro to activate the Module, if so, how?
Thus far, I can only execute the Module by pressing Run in the Module window. I'm sure there is a cleaner way to perform/execute this process. Any suggestions...?