S
Silvio
I have a form based on tblRepCity which displays the records (continuous
form) from this table. In the header section of this form, I have a Combo Box
called comCity which is based on tblCity (it has cities names only) and
stores the data in tblRepCity. What I am trying to accomplish is to
programmatically avoid adding the same city two times in the list or entering
a blank record (if a name is selected from the list and then delete with the
backspace from the keyboard). I know I can set the property in the table not
to allow duplications and that fields can not be black, however this will
generate a series of errors message and makes the process not user friendly
for my users. How can I address these problems programmatically? Doing some
research I came up with something like this but is does not seem to work
well. Any TESTED recomandation will help and please be as specific as you
can. Thank you all.
Private Sub comcity_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("City", "tblRepCity", "[city]=" & "ComCity.Value")) Then
MsgBox "City already selected"
Exit Sub
End If
Else
DoCmd.GoToRecord , , acNewRec
End If
End Sub
form) from this table. In the header section of this form, I have a Combo Box
called comCity which is based on tblCity (it has cities names only) and
stores the data in tblRepCity. What I am trying to accomplish is to
programmatically avoid adding the same city two times in the list or entering
a blank record (if a name is selected from the list and then delete with the
backspace from the keyboard). I know I can set the property in the table not
to allow duplications and that fields can not be black, however this will
generate a series of errors message and makes the process not user friendly
for my users. How can I address these problems programmatically? Doing some
research I came up with something like this but is does not seem to work
well. Any TESTED recomandation will help and please be as specific as you
can. Thank you all.
Private Sub comcity_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("City", "tblRepCity", "[city]=" & "ComCity.Value")) Then
MsgBox "City already selected"
Exit Sub
End If
Else
DoCmd.GoToRecord , , acNewRec
End If
End Sub