Hello everybody,
I think this is a problem that has been asked anytimes, so what's one more time. I have an unbound form named tbl_AddCustomer with fields like Customer,Telephone#, and Address. What I'm trying to do is prevent entries into the customer table if either the customer or telephone fields remain blank. I have the code to append properly, but my if statement isn't working. I think I'm having trouble with Null values. Here's the code.
If Me.Customer.Value = Null Or Me.Business_.Value = Null Then
Beep
MsgBox "One or more of the required fields is empty.", vbCritical, "ERROR"
End If
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Customer")
With rs
.AddNew
.Fields("BusinessCustomer") = 1
.Fields("Customer") = Me.Customer.Value
.Fields("Address") = Me.Address.Value
.Fields("City") = Me.City.Value
.Fields("Province") = Me.Province.Value
.Fields("Postal Code") = Me.Postal_Code.Value
.Fields("Business#") = Me.Business_.Value
.Fields("Fax#") = Me.Fax_.Value
.Fields("Pager#") = Me.Pager_.Value
.Fields("Email") = Me.Email.Value
.Update
End With
rs.Close
End Sub
Where am I going wrong?
I think this is a problem that has been asked anytimes, so what's one more time. I have an unbound form named tbl_AddCustomer with fields like Customer,Telephone#, and Address. What I'm trying to do is prevent entries into the customer table if either the customer or telephone fields remain blank. I have the code to append properly, but my if statement isn't working. I think I'm having trouble with Null values. Here's the code.
If Me.Customer.Value = Null Or Me.Business_.Value = Null Then
Beep
MsgBox "One or more of the required fields is empty.", vbCritical, "ERROR"
End If
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_Customer")
With rs
.AddNew
.Fields("BusinessCustomer") = 1
.Fields("Customer") = Me.Customer.Value
.Fields("Address") = Me.Address.Value
.Fields("City") = Me.City.Value
.Fields("Province") = Me.Province.Value
.Fields("Postal Code") = Me.Postal_Code.Value
.Fields("Business#") = Me.Business_.Value
.Fields("Fax#") = Me.Fax_.Value
.Fields("Pager#") = Me.Pager_.Value
.Fields("Email") = Me.Email.Value
.Update
End With
rs.Close
End Sub
Where am I going wrong?