Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Selection in CboBox not "Turning Off Fields in form" as it shoud. 1

Status
Not open for further replies.

Conner

Technical User
Nov 29, 2000
44
0
0
US
My problem is that the question I need to ask has been answered quite well in "Turn Off fields in a form based on selection made from combo box." But I can't make it work in my case...

So...here goes. I have a main form and a subform. The main form simply lets the user know they have selected their "Pin Number correct." There are no active controls on the main form. The subform (sfrmSignOut) has four active controls.

It's the subform that is causing me grief. On the subform is a combobox (cboDestination). The form/subform opens with control on this combobox. The user either enters or selects from a list of destinations. When a destination is selected, a text field on the subform (txtTime) automatically enters the time and the record saved.

The relationship between cboDestination and txtTime is controlled by an update event on the cbobox (DoCmd.RunCommand acSaveRecord). This seems to works fine.

Now what I would like to do is "turn off" the remaining two txtboxes depending upon the selection made in cboDestination. If the user signs out for the day, I want the purpose and return time to disappear.

I've written more code in the update event of cboDestination using a select case. But it isn't working. Here is my code -- where did I goof?

Private Sub cboDestination_Update()
Dim strValue as String

strValue=Me!cboDestination

Me.txtTime=Now()
DoCmd.RunCommand acCmdSaveRecord

Select Case strValue
Case "Central Office"
Me!cboPurpose.Visible=False
Me!txtEstRetTime.Visible=False
Case "Signing Out for Remainder of Day"
Me! cboPurpose.Visible=False
Me! txtEstRetTime.Visible=False
Case Else
Me! cboPurpose.Visible=True
Me! txtEstRetTime.Visible=True
End Select

I then use an event procedure on the subform, when it's opened again for another user, to make both these boxes visible again if they've been turned off by the previous user...








 
Connor:

Your code looks great, but one thing though: combo boxes don't have an update event - they have either an AfterUpdate event, or a BeforeUpdate event. Try using the AfterUpdate event, this may solve your problem.

Oh, and be sure to set the After Update property of the combo box to [Event Procedure] to get the event to actually fire. :)

HTH

Greg Tammi, IT Design & Consultation
Work: Home:
 
You are so right, and that was my mistake. The code in my question should have been "Private sub cboDestination_AfterUpdate" and not what I had: "Private sub cboDestination_Update." Like you suggested, I developed the code as part of the combobox allowed events, so I was never given the option of "Update." The events available to me made sure I looked at "after update."

I'm beginning to suspect it isn't so much the code as some logic design that is twisting things up. The fact that the "DoCmd.RunCommand acCommandSaveRecord" part of the AfterUpdate event works, but a select case added either before or after that statement seems to be ignored is really confusing me.

Let me ask this: The form/subform open. The focus is on the cbobox. The user, in theory, uses the mouse to make move through the list to make a selection.When the user click, the time (Now) of that selection appears in another control (txtBox) on the same subform. In this sequence, has the afterupdate event fired? If so, when? I tried using a MouseUp to hide the other controls after the user made a selection, but some users will not recognize that the focus is alread on the cbobox and will click before they make a selection...What I need is something that "fires" when a selection is made but before focus is moved to another control...
 
The AfterUpdate event fires as soon as the value in the combo box changes ... you could use a command to move the focus to another field after the selection and "lock" the combo box, but that brings another question into play: what do you do if the user selected the wrong item?



Greg Tammi, IT Design & Consultation
Work: Home:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top