ComboBox - check and change (or not change)

reddevil1

Registered User.
Local time
Today, 10:48
Joined
Nov 12, 2012
Messages
92
When Combo1 is updated, I check if TextBox1 is empty.

And if TextBox1 is empty then I do NOT want Combo1 to be updated (eg. I want the original selection to remain).

Please could anyone help me how to do this?
 
Hi Pat,

Thanks very much for your reply and for the suggested coding.

You have just taught a newbie in VBA a new trick.

Cheers.
 
Pat,

Everything seems to work OK apart from when I change the selection from "Cheque" to "Cash".

It keeps the new selection in the Combo. I am hoping to have the selection revert back to the original selection. I thought maybe that is what the Undo selection was for?

Please coudl anyone point out where my coding is incorrect?

Thanks.

If MethodMoneyInOut.Column(1) <> "Cheque" Then
If Len(Me.ChequeNo & "") <> 0 Then
MsgBox "Cannot change if ChequeNo contains data.", vbOKOnly
Me.MethodMoneyInOut.Undo
Cancel = True
End If
ChequeNo.Enabled = False
ChequeNo.Locked = True
ChequeNo.BackColor = 12566463
ChequeDate.Enabled = False
ChequeDate.Locked = True
ChequeDate.BackColor = 12566463
End If
 
Pat,

Thanks again for your very valuable guidance. Thanks to you I have managed to get the BeforeUpdate code to work awesomely - and the Form looks so cooooool now :) The "final"? coding is below.

I was very interested in your comments that both the True path and the False path should be stated?

I wonder if i am doing things wrong still? This is how I am currently handling things:-

BeforeUpdate event - is used only for cancelling the selection if the Combo is not "Cheque" and the ChequeNo is not empty. At the moment, I do not use the BeforeUpdate event for anything else. Is this the correct strategy????

AfterUpdate event - is used to check the fields and lock/disable them accordingly. I presume this will only activate if the selection is accepted by the BeforeUpdate event?

Form OnCurrent event - is used to check the fields and lock/disable them accordingly when the Form is first opened.

Private Sub MethodMoneyInOut_BeforeUpdate(Cancel As Integer)
If MethodMoneyInOut.Column(1) <> "Cheque" And Len(Me.ChequeNo & "") <> 0 Or Len(Me.ChequeDate & "") <> 0 Then
MsgBox "Please delete Cheque No and Cheque Date details before changing this field", vbOKOnly
Me.MethodMoneyInOut.Undo
Cancel = True
Exit Sub
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom