Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Time Field set to Null

Status
Not open for further replies.

andybeanland

IS-IT--Management
Jan 28, 2005
15
GB
Hello,

I've got a problem with a date field that I just can't resolve - hopefully you'll be able to help.

I have a series of text boxes (10 in total) which are for inserting start and end times for children attending a nursery for the different days of the week. The children don't attend every day so some of the text boxes will be left blank. How do I get Access to insert a null into a date time field?

This is the coding I have:

Dim MonS As Variant
Dim MonE As Variant

MonAtt = [Forms]!frm_Attending.Monday_Attending
MonS = [Forms]!frm_Attending.Monday_Start
MonE = [Forms]!frm_Attending.Monday_End

SQLMonday = "INSERT INTO tbl_Monday (Attending, StartTime, EndTime) VALUES ('" & MonAtt & "', '" & MonS & "', '" & MonE & "')"

DoCmd.RunSQL SQLMonday

The text boxes also have the input mask 00:00;0;_

When leaving an text box empty the error message I am getting is:

Access Can't Append All The Records In the Append Query.
Access Set 1 Field to Null due to a type conversion failure.

If the text boxes are populated the SQL is executed correctly and inserts the information into the tables.

Thanks for your help,

Andy
 
You may try this:
SQLMonday = "INSERT INTO tbl_Monday (Attending, StartTime, EndTime) VALUES ('" & MonAtt & "', " & IIf(IsDate(MonS), "#" & MonS & "#", "Null") & ", " & IIf(IsDate(MonE), "#" & MonE & "#", "Null" & ")"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PH, but I just tried the code you pasted in and it just gives me a "Compile Error. Expected: List seperator or )"

I've checked the correct number of brackets etc, but wasn't really sure what this was doing so didn't know what to check...

 
Sorry for the typo:
SQLMonday = "INSERT INTO tbl_Monday (Attending, StartTime, EndTime) VALUES ('" & MonAtt & "', " & IIf(IsDate(MonS), "#" & MonS & "#", "Null") & ", " & IIf(IsDate(MonE), "#" & MonE & "#", "Null") & ")"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top