Hello,
Ok, I had to have done this some time in the past... and yet I can't today, and I'm going to pull my hair out!
I have a form with a series of unbound text boxes where data is entered - including two non-required dates. If I use the date picker to choose a date, this works fine, but if I leave the date fields blank, I get a null conversion error.
The above is the portion of the VALUES part of my INSERT statement... what do I need to do the values (or lack there of!) in the dtmStart and dtmEnd fields to have MS Access allow me to push back null/blank? I don't want to require these two fields.
The backend is sql server 2012 and the field's properties includes being datetime and set to allow null. I'm stumped.
What do I need to do to make this allow blank/null to be allowed?
The full query, if this helps:
Help!
Thanks,
-Matt G.
Ok, I had to have done this some time in the past... and yet I can't today, and I'm going to pull my hair out!
I have a form with a series of unbound text boxes where data is entered - including two non-required dates. If I use the date picker to choose a date, this works fine, but if I leave the date fields blank, I get a null conversion error.
Code:
"', " & _
Chr(35) & dtmStart & Chr(35) & _
", " & _
Chr(35) & dtmEnd & Chr(35) & _
", '" & _
The backend is sql server 2012 and the field's properties includes being datetime and set to allow null. I'm stumped.
What do I need to do to make this allow blank/null to be allowed?
The full query, if this helps:
Code:
Private Sub btnAddNewRecord_Click()
If (Format(Trim(txtActivityName)) <> "") And (listboxGoalsObjectives.Value <> "") Then
Dim strSQL As String
strSQL = "INSERT INTO dbo_Activities (GoalObjectiveIDf, ActivityName, ActivityDesc, OrganizationalFunction, TopicalFocus, PlanningCycle, FundingSource, PeriodicDetail, KeyPerformanceIndicator, ProjectedCosts, ProjectedStaffHours, MetricType, StartDatetime, EndDatetime, PrimaryAudience) VALUES (" & _
[listboxGoalsObjectives].[Value] & ", '" & Replace(Format(Trim(txtActivityName)), "'", "''") & "', '" & Replace(Trim(Nz(txtActivityDesc, "")), "'", "''") & "', '" & _
Replace(Format(Trim(txtOrgFunction)), "'", "''") & _
"', '" & _
Replace(Format(Trim(txtTopicalFocus)), "'", "''") & _
"', '" & _
Replace(Format(Trim(cboPlanningCycle)), "'", "''") & _
"', '" & _
Replace(Format(Trim(txtFundingSource)), "'", "''") & _
"', '" & _
Replace(Format(Trim(cboPeriodicDetail)), "'", "''") & _
"', '" & _
Replace(Format(Trim(txtKeyPerformanceIndicator)), "'", "''") & _
"', '" & _
Replace(Format(Trim(numProjectedCosts)), "'", "''") & _
"', '" & _
Replace(Format(Trim(numProjectedStaffHours)), "'", "''") & _
"', '" & _
Replace(Format(Trim(txtMetricType)), "'", "''") & _
"', " & _
Chr(35) & dtmStart & Chr(35) & _
", " & _
Chr(35) & dtmEnd & Chr(35) & _
", '" & _
Replace(Format(Trim(txtPrimaryAudience)), "'", "''") & "');"
MsgBox ("strSQL: " & strSQL)
'DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
'DoCmd.SetWarnings True
txtActivityName = ""
txtActivityDesc = ""
txtOrgFunction = ""
txtTopicalFocus = ""
cboPlanningCycle = ""
txtFundingSource = ""
cboPeriodicDetail = ""
txtKeyPerformanceIndicator = ""
numProjectedCosts = ""
numProjectedStaffHours = ""
txtMetricType = ""
dtmStart = ""
dtmEnd = ""
txtPrimaryAudience = ""
listboxActivities.Requery
Else
MsgBox ("Select an Objective, then Enter Activities info before pressing ADD.")
End If
End Sub
Help!

Thanks,
-Matt G.