Solved

Correct VBA / SQL statement please

Posted on 2012-04-04
2
206 Views
Last Modified: 2012-04-04
super quick one. I don't know how to use the update statement in sql

This is the essence of what I want:


strSql = "UPDATE " & SettingsTable & "SET [LastOOSLAImportDate] = (#" & Format(Date, "yyyy-mm-dd") & "#)"

SettingsTable is a variable I've defined. LastOOSLAImportDate is a field in the SettingsTable. The table doesn't have a bunch or rows, it's a simple non-indexed table with a few settings on it I use to retrieve settings from.

I want to update the one row thats in there to set LastOOSLAImportDate to today.

Cheers
0
Comment
Question by:RossDagley1
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37805357
Is SettingsTable the name of the table or the name of a variable with the table name?

If it's the table name:
strSql = "UPDATE SettingsTable SET [LastOOSLAImportDate] = (#" & Format(Date, "yyyy-mm-dd") & "#)"

Open in new window

If it's a variable with the table name:
strSql = "UPDATE [" & SettingsTable & "] SET [LastOOSLAImportDate] = (#" & Format(Date, "yyyy-mm-dd") & "#)"

Open in new window

Which is basically the same as your code, but wiht [] added in case the table name has spaces.
0
 
LVL 2

Author Comment

by:RossDagley1
ID: 37805363
strSql = "UPDATE [" & SettingsTable & "] SET [LastOOSLAImportDate] = (#" & Format(Date, "yyyy-mm-dd") & "#)"
                                            

Open in new window


That's the ticket - thanks very much. I just couldn't get the formatting right!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now