I have a form where I want either Asset or Location filled out and Supervisor or Lead or Crew or Work Group or Crew Work Group. I have the code and it works but it only allows me to enter numbers into these fields. I want to be able to enter numbers and letters into these fields.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Form_frmAddPM.Asset Or Form_frmAddPM.Location) Then
MsgBox "Please enter a value in an asset or location."
Cancel = True
End If
If IsNull(Form_frmAddPM.Supervisor Or Form_frmAddPM.Lead Or
Form_frmAddPM.Crew Or Form_frmAddPM.Work_Group Or
Form_frmAddPM.Crew_Work_Group) Then
MsgBox "Please enter value in Supervisor, Lead, Crew, Work Group, or
Crew
Work Group."
Cancel = True
End If
End Sub
I have tried to change integer to different types. With the code above when I try to enter letters into the form a mismatch type error pops up.
Thank you in advance for your help.
You're using the bitwise
OR
operator, which requires both values you use it on to be an integer (see the docs, VB.Net but works the same in VBA)Instead, you should check for each field if it's null separately: