Assigning a table field value as a VB variable

G

Guest

I am trying to update a field in an access table with a variable. I am
deleting out a date table and trying to replace it w/ the variable "RunDate",
I think I am missing adding in the # before and after RunDate, but I have
tried this in multiple places and keep getting a compile error. Below is
what I have, any help would be appreciated.

CurrentDate= Format(Date, "Short Date")
RunDate = DateAdd("D", -2, CurrentDate)
selString = "update PARM_RunDt_tbl set RunDt = " & RunDate & ""
DoCmd.SetWarnings False
DoCmd.OpenQuery "PARM_RunDt_tbl - Delete", acNormal, acEdit
DoCmd.RunSQL selString
 
D

Duane Hookom

Don't format your date in the code. You don't say what the PARM_RunDt_tbl -
Delete does or why you are running it.

Try:

selString = "update PARM_RunDt_tbl set RunDt = DateAdd('D', -2, Date())"
DoCmd.SetWarnings False
DoCmd.OpenQuery "PARM_RunDt_tbl - Delete", acNormal, acEdit
DoCmd.RunSQL selString
DoCmd.SetWarnings True
 
G

Guest

I didn't get a compile error with this, but it didn't update my table, the
field is still blank. The PARM_RunDt_tbl- Delete is deleting all
records(should always only be one) from the PARM_RunDt_tbl. I am using this
table to populate the date field in several other create queries. I am
basically trying to replace an update query for this table w/ the VB code so
I can run this automatically everynight.
 
D

Duane Hookom

If you delete all the records in the table then it does no good to run an
udpate query against the table. There are no records to update. Maybe you
need to tell us what you are attempting to do.
 
G

Guest

You answered my question. I am used to running a delete query and then an
update query. When I removed the delete query the SQL update worked. Thanks!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top