You will need to put this on the form UNLOAD event if you want it to
look at the form you are closing for values... if you wait until the
CLOSE event, the form will already have been unloaded...
Building on to what Fred gave you, I have use line continuation sysmbols
_ (just in case the lines break) and assigned your SQL to a string so
that you can debug it
dim strSQL as string
strSQL = "Update [tbl-offsites] " _
& " SET ReleasedDate = #" & Date() & "#" _
& " WHERE [Vault No] = " & nz(Me![Vault No]) & ";"
debug.print strSQL
CurrentDb.Execute , dbFailOnError
and, then, if [Vault No] is text, you will need to delimit it
& " WHERE [Vault No] = '" & nz(Me![Vault No]) & "';"
I have also used NZ (null to zero) in case the field is not filled out
~~~~~
debug.print strSQL
--> this prints a copy of the SQL statement to the debug window (CTRL-G)
If you have problems after you run it, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement
If the SQL statement has an error
1. Make a new query (design view)
2. choose View, SQL from the menu (or SQL from the toolbar, first icon)
3. cut the SQL statement from the debug window (select it and then CTRL-X)
4. paste into the SQL window of the Query (CTRL-V)
5. run ! from the SQL window -- Access will tell you where the problem
is in the SQL
Have an awesome day
Warm Regards,
Crystal
MVP Microsoft Access
strive4peace2006 at yahoo.com
I have the following code attached to the on close command of a form
but I get a error saying the "sub or function not defined" One step
forward three steps back!!!
Private Sub Form_Close()
Update [tbl-offsites]
Set ReleasedDate = Date
where [forms!frmrelease]![Vault No] = [Vault No]
End Sub
What is the datatype of [Vault No]?
Number datatype?
What is the name of the form on which this code is placed?
"frmRelease"? You can substitute the Me keyword for forms!frmRelease.
Private Sub Form_Close()
CurrentDb.Execute "Update [tbl-offsites] Set
[tbl_offsites].ReleasedDate = Date() where [tbl-offsites].[Vault No]
= " & Me![Vault No] & ";", dbFailOnError
End Sub
Text datatype?
CurrentDb.Execute "Update [tbl-offsites] Set
[tbl-offsites].ReleasedDate = Date() where [tbl-offsites].[Vault No]
= '" & Me![Vault No] & "';", dbFailOnError