COMBO BOX

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a combo box on form 1. Once the user selects an item in the combo
box, form 2 pops up asking for a password. This is where I have a problem.
If the user doesn't know the password and clicks on a button, the combo box
on form 1 should show what it was before the user changed it. Does anyone
know how to do this? Any help is appreciated.

Thanks.
ash
 
Capture the value of Combo1 to a variable before the user changes it. Then
you can change it back easily.

Private Combo1_BeforeUpdate()
Dim Combo1Temp
Combo1Temp = Combo1 'snapshot of its current value
End Sub

Private Combo1_AfterUpdate()
If InputBox("Enter password") = "12345" Then ' where 12345 is the password
DoCmd.OpenForm "form2"
Else
Combo1 = Combo1Temp
End If
End Sub

This requires the password test to be on form1 instead of form2. If it must
be on form2, it gets more complicated. Post a followup if you must do it that
way.
 
Brian,

I am still not able to capture the value of the combo box. This is my code.
I stepped through the debug to see what was wrong. In my before update,
strTemp is null, while work release is "released". It doesn't seem like
strTemp was passed from the Before Update to After Update. Please let me
know what I did wrong. Thanks for the hellp.

Private Sub WORK_RELEASE_BeforeUpdate(CANCEL As Integer)
Dim strTemp As String
strTemp = WORK_RELEASE
End Sub

Private Sub WORK_RELEASE_AfterUpdate()
If InputBox("Please enter the password") = "12345" Then
If Me.WORK_RELEASE = "RELEASED" Then
Me.TITLE.Locked = True
Me.ORGANIZATION.Locked = True
Me.DATE.Locked = True
ElseIf Me.WORK_RELEASE = "CANCELLED" Then
Me.ORGANIZATION.Locked = True
Me.DATE.Locked = True
ElseIf Me.WORK_RELEASE = "WORKING" Then
Me.TITLE.Locked = False
Me.ORGANIZATION.Locked = False
Me.DATE.Locked = False
End If
Else
Me.WORK_RELEASE = strTemp
End If
End Sub
 
Oh, yes, you have to capture WORK_RELEASE.OldValue because (even though you
are in BeforeUpdate) its value will already resolve to the
newly-entered/selected value.

Put this in the Before_Update
strTemp = WORK_RELEASE.OldValue

This is assuming that strTemp is a bound combo box (i.e. has a Control
Source). If it is unbound, then you need to set strTemp = WORK_RELEASE
immediately after the original value of WORK_RELEASE is set. This is because
the .OldValue property only applies to bound controls

Sorry for the misstatement in round 1.
 
I am still having a problem with capturing the value of the combo box.
strTemp is still not capturing the old value of the combo box. When I step
through the code, WORK_RELEASE.OldValue = "Working" but strTemp = "". Somehow
the value is not passed to the string.

Put this in the Before_Update
strTemp = WORK_RELEASE.OldValue
 
Ash,

strTemp is not getting a value because it is out of scope. It only exists
for as long as the BeforeUpdate procedure executes, then poof!

You can declare a public variable in a global module, but it's easier just
to write the value out to an invisible control on your form both in the
form's OnCurrent event and the combo box' AfterUpdate event.

Hope that helps.
Sprinks
 
Good catch. I missed the variable declaration and was assuming that strTemp
was a control name, not a variable. Thanks for the correction.
 
I still can't get the old value to show if the user did not put the password
in, hits enter or cancels on the input box. I tried what you suggested. I
have an invisible text box on the form called TXT_OLD_VALUE_WORK_RELEASE. I
don't know what I did wrong.

Private Sub Form_Current()
Me.TXT_OLD_VALUE_WORK_RELEASE = Me.WORK_RELEASE
End Sub

Private Sub WORK_RELEASE_AfterUpdate()
If InputBox("Please enter the password") = "12345" Then
If Me.WORK_RELEASE = "RELEASED" Then
Me.TITLE.Locked = True
Me.ORGANIZATION.Locked = True
Me.DATE.Locked = True
ElseIf Me.WORK_RELEASE = "CANCELLED" Then
Me.ORGANIZATION.Locked = True
Me.DATE.Locked = True
ElseIf Me.WORK_RELEASE = "WORKING" Then
Me.TITLE.Locked = False
Me.ORGANIZATION.Locked = False
Me.DATE.Locked = False
End If
Else
Me.TXT_OLD_VALUE_WORK_RELEASE = Me.WORK_RELEASE
End If
End Sub
 
The Form_Current needs to set the old value to the current value, while the
Else clause of your WORK_RELEASE_AfterUpdate needs to reverse that. Turn this
line around (the one below the Else, not the one in Form_Current), and you
can leave out the "Me", since it is understood if left out:

Me.TXT_OLD_VALUE_WORK_RELEASE = Me.WORK_RELEASE

I think should be just this:

WORK_RELEASE = TXT_OLD_VALUE_WORK_RELEASE

You might temporarily make TXT_OLD_VALUE_WORK_RELEASE visible to see if the
value is being correctly set there.
 
Back
Top