Disable / re-enable form field & events (re-post)

G

Guest

Hi - Am using Access ('02) to input a photo archive from a truck body
manufacturer. Have set up the following fields:
Reason (why photo was taken). Most pics are "Portraits", in which case we
list a:
BodyStyle (tank, delivery, milk, fire pumper, beer, tow, etc.)
Other reasons are Insurance, plant views, and truck show pics. (No BodyStyle)

I have figured out how to disable the bodystyle combo box in my form when
reason is not portrait using:
Private Sub cboReason_AfterUpdate()
If Not 1 Then Me.cboBodyStyle.Enabled = False
End Sub
(1 = portrait, which is default), AND
Private Sub Form_AfterUpdate()
Me.cboBodyStyle.Enabled = True
End Sub
to re-set the control when moving to the next entry. Is this the right event
to re-enable the bodystyle box? (My first efforts at code from scratch and
these actually work - what a thrill!)

If a user changes the reason accidentally, then changes back to portrait,
the bodystyle box is still disabled. Not so good. So I added:

Private Sub txtSubjComment_GotFocus()
Dim Msg, Style
'Define message
Msg = "If you need to change the body style, hit F9"
'define style
Style = vbOKOnly
'Display message
Response = MsgBox(Msg, Style)
End Sub
SubjComment is the next field after Reason & BodyStyle.
(Even this works!) It does what I tell it, but all the time, which is very
annoying. Obviously I'm working with the wrong event, or else I need to add
another condition?

Should it be something like
if cboReason_AfterUpdate = 1 then Response = MsgBox
Just tried it and that didn't work.

Should I be changing the event or adding qualifiers to
txtSubjComment_GotFocus or both?? Or doing something completely different?

If going the message box route, I guess my conditions / the logic should be:
If Reason=Portrait and BodyStyle.Enabled = false
then make the message box appear (?) How?

I wanted to do this with a Macro but couldn't figure out what action would
disable the combo box.
Thanks very much - Lisa
 
W

Wayne Morgan

Private Sub cboReason_AfterUpdate()
If Not 1 Then Me.cboBodyStyle.Enabled = False
End Sub

You disable the BodyStyle combo here, but you're not doing anything to
reenable it if the value is 1.

Me.cboBodyStyle.Enabled = (Me.cboReason = 1)

Use the above instead of the If statement. To explain this statement, the
right side of the first equal sign will return True or False, depending on
whether cboReason = 1. The True or False will be assigned to the Enabled
property of cboBodyStyle.

You could also add an Else to your If statement instead and enable
cboBodyStyle in the Else part of the If statement.

If Me.cboReason <> 1 Then
Me.cboBodyStyle.Enabled = False
Else

Me.cboBodyStyle.Enabled = True
End If
 
G

Guest

Wayne - thanks. Have to get off line before I can try this out, but it looks
clear. If not, I'll be in touch. Thanks again! - Lisa
 

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