Joselin
Mar 11 2004, 03:30 AM
In my form there is a field known as CurrencyCombo. I want the user to select currency from this CurrencyCombo before proceed to the rest of the fields. If the user didn't select the CurrencyCombo, then i want it to set focus back to CurrencyCombo until the user select.
Below is the code:
Private Sub CurrencyCombo_Enter()
If Me.CurrencyCombo = Null Then GoTo CurrencyComboErr
If Me.CurrencyCombo <> "" Then GoTo ExitSub
CurrencyComboErr:
MsgBox "Please select currency"
Me.CurrencyCombo.SetFocus
If Me.CurrencyCombo = Null Then GoTo CurrencyComboErr
ExitSub
ExitSub:
End Sub
After i run this code, the user still able to go to other field eventhough the user didn't select currency.
How can i make so that the user have to select the currency and "disable" to get out of this field if the user didn't select the currency?
danishani
Mar 11 2004, 03:36 AM
Place this code in the AfterUpdate event of the combobox;
If Me.CurrencyCombo = Null Then
MsgBox "Please select currency"
Me.CurrencyCombo.SetFocus
Docmd.GoToControl "CurrencyCombo"
Else
Exit Sub
End If
Daniel
Joselin
Mar 11 2004, 04:10 AM
Dear Daniel:
I tried the below code:
Private Sub CurrencyCombo_AfterUpdate()
If Me.CurrencyCombo = "" Then GoTo CurrencyComboErr
If Me.CurrencyCombo <> "" Then GoTo CurrencyComboExit
CurrencyComboErr:
MsgBox "Please select currency"
Me.CurrencyCombo.SetFocus
DoCmd.GoToControl "CurrencyCombo"
GoTo ExitSub
CurrencyComboExit:
Me.InvoiceExchangeRate = Forms!Invoice!CountryCodeSubform!ExRateFXtoMYR
DoCmd.RunCommand acCmdSaveRecord
GoTo ExitSub
ExitSub:
End Sub
BUT it still doesn't work. The user still can leave the currency field blank without selecting it from the combo box.
What wrong with my code?
danishani
Mar 11 2004, 04:28 AM
Hmmm weird,
Maybe workaround, there must be an easier way to do this, set the validation rule in the field properties of the field which is related to the combobox...
Daniel
danishani
Mar 11 2004, 04:34 AM
Or if its always required, then set the field propperties on Required.
Daniel
Joselin
Mar 11 2004, 04:42 AM
ok
thanks
Larry Larsen
Mar 11 2004, 05:03 AM
Hi
Would it a better option to place your code in the "BeforeUpdate" event of the form, placing your code in the "afterupdate" event of the combo will not trigger "unless" you select something?.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.