Hi All!
I have a form that allows me to insert data into my access database. In that form I have a date field and when it is null I get an error for data mismatch. How do I avoid inserting that field if it is null?
I read that access has a strongly typed field setting that stops nulls from being inserted.
Here is my code:
Private Sub CommandButton2_Click()
txt = TextBox4.Text
TextBox4.Text = Replace(txt, "'", "")
Dim Conn1 As New ADODB.Connection
Dim Cmd1 As New ADODB.Command
Dim AccessConnect As String
On Error GoTo Error1
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=TestFT.mdb;" & _
"DefaultDir=C:\Documents and Settings\chris\Desktop\FT Data;" & _
"Uid=Admin;Pwd=;"
Conn1.ConnectionString = AccessConnect
Conn1.CursorLocation = adUseClient
Conn1.Mode = adModeReadWrite
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "UPDATE PlanningData SET Job = " & UserForm1.TextBox2 & ", Planning_ACD = '" & UserForm1.TextBox3 & "', Planning_Notes = '" & UserForm1.TextBox4 & "' WHERE FA_Number = " & UserForm1.TextBox1 & ""
Cmd1.Execute
Conn1.Close
Conn1.ConnectionString = ""
Range("e6").Select
Exit Sub
Error1:
MsgBox "Please contact Chris with the error description: " & Err.Description
CutCopyMode = False
End Sub
I have a form that allows me to insert data into my access database. In that form I have a date field and when it is null I get an error for data mismatch. How do I avoid inserting that field if it is null?
I read that access has a strongly typed field setting that stops nulls from being inserted.
Here is my code:
Private Sub CommandButton2_Click()
txt = TextBox4.Text
TextBox4.Text = Replace(txt, "'", "")
Dim Conn1 As New ADODB.Connection
Dim Cmd1 As New ADODB.Command
Dim AccessConnect As String
On Error GoTo Error1
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=TestFT.mdb;" & _
"DefaultDir=C:\Documents and Settings\chris\Desktop\FT Data;" & _
"Uid=Admin;Pwd=;"
Conn1.ConnectionString = AccessConnect
Conn1.CursorLocation = adUseClient
Conn1.Mode = adModeReadWrite
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "UPDATE PlanningData SET Job = " & UserForm1.TextBox2 & ", Planning_ACD = '" & UserForm1.TextBox3 & "', Planning_Notes = '" & UserForm1.TextBox4 & "' WHERE FA_Number = " & UserForm1.TextBox1 & ""
Cmd1.Execute
Conn1.Close
Conn1.ConnectionString = ""
Range("e6").Select
Exit Sub
Error1:
MsgBox "Please contact Chris with the error description: " & Err.Description
CutCopyMode = False
End Sub