Before Update not checking combobox!

G

Guest

I have 2 comboboxes on my form, (AcctDecision, AcctCode)
AcctDecision has the following values in it... (Accept, Deny, Pending)
AcctName has the following names ( XYZ, ABC, DEF)

So what I am getting into is that if I select Pending in the AcctCode
Combobox, I need to select something in the AcctName. My code is making me
be able to save the record with the ACCTName blank when the Acct Code is
Pending.

Dim StrControl as string

strControl = ""
If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
strControl = strControl & "Select an Account Name" & vbCrLf
Cancel = True
End If

if strControl <>"" then
msgbox " Enter missing informatio": & vbcrlf & strcontrol,
vbinformation, "Incomplete Information"
End if
 
A

Allen Browne

Move the code into the BeforeUpdate event of the *form*, not that of the
control.

You have no idea which box the user will fill in first, or which order they
will change them. Form_BeforeUpdate will fire just before the record is
saved, so cancelling this event will prevent the save.
 
G

Guest

Two things to check first
1. If you are entering the code.
Put a code break on the first line of the code (Press F9 while the cursor on
this line), then step the code using the F8 key

2. Check the value of Me!AcctCode if it's Null or empty.
You can use

If Me!AcctDecision.Column(1) = "Pending" And len(Me!AcctCode & "") = 0 Then
 
A

Allen Browne

If you are using Form_BeforeUpdate, and the event is not cancelling, then
the condition is not being met.

For debugging purposes, break the line into 2:

If Me!AcctDecision.Column(1) = "Pending" Then
Debug.Print "Pending"
If IsNull(Me!AcctCode) Then
Debug.Print "AcctCode is null. Cancelling."
Cancel = True
strControl = strControl & "Select an Account Name" & vbCrLf
End If
End If

Add an inappropriate record, and see which part of the condition is not
being met. For example, the second column of your combo may not contain
"Pending" (remember the Column() property is zero-based), or the AcctCode
might contain a zero-length string instead of a null (which you can avoid by
setting its Allow Zero Length property to No in table design.)
 
G

Guest

I tried as you said but the part that is not being met is the If
IsNull(Me!AcctCode) Then
Everything else seems to be working ok, using the code you wrote. that
cmbobox is supposed to have something only when Pending is selected.
Any other reason this could be misbehaving....
 
G

Guest

It worked, since my 2nd control was a cmbbox, I added .column(0) and it
worked! thatnks for your input!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top