You were supposed to show us the debug.print results from the immediate window.
this one?? This is the window that came out after running the code???
You were supposed to show us the debug.print results from the immediate window.
Just a reminder of the objective.
Substituting Date() for Now() is not a solution.
I made a suggestion that avoids having to format the date and so should avoid the issue with the a.m., assuming that is what is causing the problem. I doubt the OP tried it though.
Make a querydef and save it:
Insert Into YourTable (YourDate, YourFK)
Values Forms!YourForm!YourDate, Forms!YourForm!YourFK;
Then run the querydef rather than an SQL String.
Assuming that Forms!YourForm!YourDate is bound to a date/time data type OR if unbound has a format property that indicates the control should hold a date, you don't need to format anything. The internal double precision number will be used so no formatting will get in the way.
Another solution assuming you insist on using embedded SQL Strings would include concatenating a string formatted as yyyy/mm/dd with a space followed by a string formated as Short Time could work since Short Time uses the 24 hour clock and so doesn't use the AM/PM designators.
dim strDate as String
strDate = Format(YourDate, "yyyy/mm/dd") & " " & Format(YourDate, "Short Time")
Then use strDate bracketed with #'s when building the SQL string.
No, the Debug.Print output in the VBA Immediate Window which is located below the code window, assuming it is active. Google "Access VBA Immediate Window" and "Access VBA Debug.Print". Here is one tutorial https://www.techonthenet.com/access/tutorials/vbadebug2010/debug07.php
Learn debugging techniques.
Append query creates a new record. You said you want to update existing record.
The string looks good so can you verify.
All table names are correct
All field names are correct
(double check all spelling)
Fecha_real is a date field
Event_ID is a numeric field
Status_ID is numeric
I said to double check your spelling
Evento_ID and Event_ID are not the same.
These are the type of errors that take a second set of eyes.
Hi. Glad to hear you got it sorted out. Good luck with your project.You are right!!!!!
That was the problem!!! a single letter!!!! Now it works properly!!!!
Thank you very much for your help MajP, June7, Pat Hartman, theDBguy. I really appreciate your help
Function SQLDate(varDate As Variant) As String
'Purpose: Return a delimited string in the date format used natively by JET SQL.
'Argument: A date/time value.
'Note: Returns just the date format if the argument has no time component,
' or a date/time format if it does.
'Author: Allen Browne. allen@allenbrowne.com, June 2006.
If IsDate(varDate) Then
If DateValue(varDate) = varDate Then
SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#")
Else
SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
End If
End If
End Function
If you want to include the time you can. I use this function most of my time on my dates.
so just modify the update string and replace the format I provided with
SqlDate(me.fechaReal)
Code:Function SQLDate(varDate As Variant) As String 'Purpose: Return a delimited string in the date format used natively by JET SQL. 'Argument: A date/time value. 'Note: Returns just the date format if the argument has no time component, ' or a date/time format if it does. 'Author: Allen Browne. allen@allenbrowne.com, June 2006. If IsDate(varDate) Then If DateValue(varDate) = varDate Then SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#") Else SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#") End If End If End Function