If & Select Case Codes

Mahoney

Registered User.
Local time
Today, 13:50
Joined
Feb 4, 2009
Messages
28
Hello,

I have a form which includes the following fields,
Dispatch Method (Combobox)
AWB (Text Box)
Tape Format (Combobox)

Dispatch Method has the following choices; DHL, FEDEX, UPS, Sky Net, Satellite & Email.

I want "AWB" and "Tape Format" to be disabled when I choose "Email" as "Dispatch Method", and enabled when I choose any of the other
Also I want "AWB" (only) to be disabled when i choose "Satellite" as "Dispatch Method"

I have tried the If Then and it did not work, i also tried the following Select Case code (I assume it is better in this case)

Private Sub DispatchBy_AfterUpdate()
Select Case DispatchBy
Case "Aramex"
AWB.Enabled = True
TapeFormat.Enabled = True
Case "DHL"
AWB.Enabled = True
TapeFormat = True
Case "Email"
AWB.Enabled = False
TapeFormat.Enabled = False
Case "FedEx"
AWB.Enabled = True
TapeFormat.Enabled = True
Case "Satellite"
AWB.Enabled = False
TapeFormat.Enabled = True
Case "Sky Net"
AWB.Enabled = True
TapeFormat.Enabled = True
Case "UPS"
AWB.Enabled = True
TapeFormat.Enabled = True
End Select

End Sub

I also disabled AWB and TapeFormat in the on current event


But still not working well,

Help Please

Many thanks
 
Try this:

Code:
Private Sub DispatchBy_AfterUpdate()
	Select Case DispatchBy
		Case "Email"
			Me.AWB.Enabled = False
			Me.TapeFormat.Enabled = False
		Case "Satellite"
			Me.AWB.Enabled = False
			Me.TapeFormat.Enabled = True
		Case "UPS", "Sky Net", "FedEx", "DHL", "Aramex"
			Me.AWB.Enabled = True
			Me.TapeFormat.Enabled = True
	End Select
End Sub
 
many thanks Banana, however it did not work.

Might there be anything on the properites that have to be changed? casue am sure the code you gave me and the codes i tried are correct

thanks
 
Wait, I just realized-

Are you sure your textboxes and comboboxes are in fact named "AWB" or "TapeFormat", and not something like "Text01", "Combo02", etc? You can verify that by going to the form's design view, opening the properties Windows (alt+enter) and clicking the textbox then on properties windows click "Other" tab to see the Name property.

It's a good habit to change the controls name to something like "txtAWB" and "cboTapeFormat" so we know when we're referring to the controls itself and not the fields bound to the controls.
 
Intellisense would indicate whether you have the correct fields, wouldn't it?
Are we sure that the Afterupdate event is the correct event?
I would favour the Beforeupdate.

Brian
 
Good point about the intellisense, Brian. (In case you don't know what it is, it's that little popup menu in VBA editor when you type something, highlighting all possible properties, methods and controls name)

As for events, BeforeUpdate wouldn't work in this instance because we'd be looking the old data or no data; and this isn't really a data validation but more of entry management by enabling/disabling other controls depending on the values selected.
 
I'm no expert on this but I would have thought that data entry management was needed before the update.

Brian

On rereading realised that it was the controls afterupdate event, I had thought it was the forms that you were using. Sorry.
 
Last edited:
The names are correct, might it be not working becasue this form is a subform on another form?
 
what is happening after adding the select case. when i go back to the form, it is keeping the disabled boxes disabled even when i select an option that should have these boxes enabled

so it seems that the code of having the AWB and Tapeformat disabled on forms currect event is being superior over the the code of after update for dispatchby
 

Users who are viewing this thread

Back
Top Bottom