[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1621
  • Last Modified:

MS Access VBA to run an update query after clicking a form's button

Hello Experts,
I am new to Access VBA programming. I am trying to build a code that reads the value in one of my form's text box and update a table (which has only one row of data/recordset). I tried various ways but I am getting error (I have attached the screenshot below). I have attached below the code I am using. I am using Access 2003. Please help.
Kindly let me know if you have any questions/concerns.
Thank you so much.
Private Sub CmdSetValues_Click()
Dim AsOfDate As Date
Dim strSQL As String
AsOfDate = Me.txtAsOfDate
strSQL = "UPDATE tblAsOfDate SET tblAsOfDate.[As of Date] = #" & AsOfDate & "#"
CurrentDb.Execute (strSQL)
End Sub

Open in new window

untitled.bmp
0
sstampf
Asked:
sstampf
  • 5
  • 4
2 Solutions
 
rockiroadsCommented:
In the vba editor, click on Debug menu option then select Compile. If there are any code problems, it will get highlighted. It is also worth checking for missing references, so again from vba editor, click on Tools then References. if any are listed as missing, the word MISSING will appear towards the top
0
 
sstampfAuthor Commented:
Thanks for your quick response rockiroads, I tried both the options you mentioned above. There are no missing references and after compiling I didn't got any error.
After that I tried using my form but I am facing the same problem again. Can you please tell me if the code I have written is correct?
Thanks
Shashank
0
 
sstampfAuthor Commented:
I am attaching below the screenshot of my form design.
untitled.JPG
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
rockiroadsCommented:
what format is the date entered in the textbox ?
0
 
rockiroadsCommented:
Do note the sql you have will update all records because there is no where clause specified

Nothing wrong with your code that I can see, only thing might be the date entry
0
 
sstampfAuthor Commented:
No, since i was testing this form so ensured that I was entering a valid date in the txtAsOfDate box (at one point of time I also experimented with CDate function but was getting the same error). Also the table tblAsOfDate contains only one record set (which I am using to pass arguments to other queries) so I didn't used the where clause.
 
0
 
rockiroadsCommented:
no worries. what format do you enter the date in?
0
 
sstampfAuthor Commented:
Thank you so much rockiroads for your prompt response. I was able to fix the problem. I just made a new form and used the same old code. I think I made some error while setting the property of the form which was leading me to this problem. Actually I was trying to put the form on full screen mode, remove min-max buttons, navigator buttons, etc. May be I did something wrong somewhere. But the good news is that my new form is working fine.
I really appreciate all your help.
Thanks
Shashank
0
 
rockiroadsCommented:
Sometimes this kind of corruption occurs. Perhaps next time, just try creating another control first before going the whole way with the form. Other thing possibly is when entering name via the properties, you may of inadvertently entered a non alphanumeric character

Using the intellisense menu is handy as when you do Me followed by dot (Me.) it lists all the properties and methods available to you.

Glad you got it going though, good luck with the rest of your project.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now