HI, I am using the code below to send data from a excel userform to an access table. I get a data mismatch at the line ".Fields("account_no").Value = textname2" In access this is a number field. If I the user fills in the account number in the user form, the data is submitted correctly. If they leave it blank then they get the data type mismatch. How can I avoid this error. I need the form to be submitted regardless or not if the field is blank.
Thanks in advance.
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim wsh As Excel.Application
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Table Name", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
With rst
.AddNew
.Fields("name").Value = textname
.Fields("name2").Value = textname1
.Fields("account_no").Value = textname2
.Update
End With
Bookmarks