I am having trouble running a query with vba. I can click the query on the left had side and it works perfectly. But when i try to run the query using a button on a form it does not work and gives the error "Object variable or With block variable not set".
more detail of the form
What i have is a multiple items form that loads of a date range query. On that form users place a check mark next to each record they want the query to affect and then type in an unbound text box what they want update the records with. Again, i can open the form, make my selections, type in my change into the unbound box, and run the query by clicking on it on the left just fine. I just cant seem to get the button to work.
Below is the SQL view of the query i am attempting to run and below that is the vba code i am using to execute the query.
Can anyone please tell me what i am doing wrong and how to fix it?
more detail of the form
What i have is a multiple items form that loads of a date range query. On that form users place a check mark next to each record they want the query to affect and then type in an unbound text box what they want update the records with. Again, i can open the form, make my selections, type in my change into the unbound box, and run the query by clicking on it on the left just fine. I just cant seem to get the button to work.
Below is the SQL view of the query i am attempting to run and below that is the vba code i am using to execute the query.
Can anyone please tell me what i am doing wrong and how to fix it?
Code:
UPDATE [C&D data] SET [C&D data].[Rel By] = [Forms]![CD_relinquish_qry_frm]![relby]
WHERE ((([C&D data].update)=True));
Code:
Private Sub updatetbl_btn_Click()
Dim dbs As DAO.Database, strupdate As String
strupdate = "UPDATE [C&D data] SET [C&D data].[Rel By] = [Forms]![CD_relinquish_qry_frm]![relby] " & vbCrLf & _
"WHERE ((([C&D data].update)=True));"
dbs.Execute strupdate
End Sub