Combo box and required record problem

newby2VBA

Registered User.
Local time
Today, 05:47
Joined
Feb 6, 2010
Messages
45
Is this the place for VBA help?
 
I think I'm in the right place so here goes
I have a combo box on a form linked to my employee table.
The combo box is called cbocity and get it data from the citytable and I was able to use vba to open the city form to add to the list of values when the city was not in the list to begin with.
Now that I made the city field require in the employee table I can't go an update the record on the other form.
Is there a solution to this?
 
I think I'm in the right place so here goes
I have a combo box on a form linked to my employee table.
The combo box is called cbocity and get it data from the citytable and I was able to use vba to open the city form to add to the list of values when the city was not in the list to begin with.
Now that I made the city field require in the employee table I can't go an update the record on the other form.
Is there a solution to this?

here is the code were xxx is City
Private Sub XXX_DblClick(Cancel As Integer)
'Double click to go to the form the dropdown refers to enter a new entry.
On Error GoTo Err_XXX_DblClick
Dim lngXXX As Long
If IsNull(Me![XXX]) Then
Me![XXX].Text = ""
Else
lngXXX = Me![XXX]
Me![XXX] = Null
End If
DoCmd.OpenForm "XXXFrm", , , , , acDialog, "GotoNew"
Me![XXX].Requery
If lngXXX <> 0 Then Me![XXX] = lngXXX
Exit_XXX_DblClick:
Exit Sub
Err_XXX_DblClick:
MsgBox Err.Description
Resume Exit_XXX_DblClick
End Sub
 
Please Help me with this I want to go Home It's Friday
 
Last edited:
I would:

  1. Keep your original, working code for adding a new city
  2. Remove the Required from the field
  3. Use validation code to ensure that a city is selected
Use code like this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Nz(Me.cboCity, "") = "" Then
   MsgBox "You Must Select a City Before Saving this Record!"
   Cancel = True
   cboCity.SetFocus
   cboCity.Dropdown
 End If
End Sub
 
I would:

  1. Keep your original, working code for adding a new city
  2. Remove the Required from the field
  3. Use validation code to ensure that a city is selected
Use code like this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Nz(Me.cboCity, "") = "" Then
   MsgBox "You Must Select a City Before Saving this Record!"
   Cancel = True
   cboCity.SetFocus
   cboCity.Dropdown
 End If
End Sub

Thanks that seems to Work
I also found that when I changed null in my code to 0 it also worked.
Now I have two options it seems.
 

Users who are viewing this thread

Back
Top Bottom