Update Qry not working whilst using VBA (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 14:38
Joined
Dec 1, 2014
Messages
401
Hi All

Having an issue with a form and an update query. I have one update query that and make in query design (Image attached (update query working). I click a command button and run the following vba and it work:

Code:
Dim dbs As DAO.Database
Set dbs = CurrentDb

            dbs.Execute ("qry_batchupdate")
            Me.Sub_Batch.Form.Requery

This works fine. I have another command button that when i click it i need it to look at a txtbox in the form and run an update query to a field based on the input in the text box. For example in the txt box it may say batchno 5033. I need it to look in the table data and find that batch no only and then mark another field in the table as false. See image of how i have done this (update query not working). I then use the code:

Code:
  Dim dbs As DAO.Database
            Set dbs = CurrentDb
            
            dbs.Execute ("Qry_AllowReprints")

I keep getting an erorr code come up saying "run time error 3061 too few parameters. expected 1". THe field names match the table so i cant understand what i have done wrong.
WOrking Update Query.JPG
 

Attachments

  • Update Query Not Working.JPG
    Update Query Not Working.JPG
    47.4 KB · Views: 46

Ranman256

Well-known member
Local time
Today, 09:38
Joined
Apr 9, 2015
Messages
4,337
you dont need dbo to run a query.

you only need 1 line: docmd.openquery "MyQryName"

and it may tell you the params needed. but you do have embedded queries there.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:38
Joined
Oct 29, 2018
Messages
21,473
Instead of using dbs.Execute, try using this one


For example
Code:
fExecuteQuery "Qry_AllowReprints"
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:38
Joined
Feb 28, 2001
Messages
27,186
Something to try, it's easy so if it doesn't work it didn't cost much.

Code:
dbs.Execute ("Qry_AllowReprints")

Remove the parentheses around the name of the query. The syntax you used changes the name of the query into an expression, which might be confusing to the Execute function.
 

Users who are viewing this thread

Top Bottom