How to close a form based on item in combo box

S

SylvieB

Hello
I have a combo box with a drop down of 4 items. Right now, if I select any
of them, the form closes and pass on the data to another form , the only
problem is this should happen only if Item 1 is seIected. If item 2,3 and 4
are selected, it should just close the form. I don’t know how to filter it.
Any ideas?
Here is the code I wrote:

Private Sub txtClosedReason_AfterUpdate()
Dim strWhere As String
strWhere = "ID= " & Me.ID
DoCmd.Close
DoCmd.OpenForm "opportunities details", whereCondition:=strWhere
End Sub

Thank you for any help.
 
G

Graham Mandeno

Hi Sylvie

Use an If statement to test the value of the combo box:

Private Sub txtClosedReason_AfterUpdate()
Dim strWhere As String
If txtClosedReason = <the option to chain> Then
strWhere = "ID= " & Me.ID
DoCmd.OpenForm "opportunities details", whereCondition:=strWhere
End If
DoCmd.Close acForm, Me.Name
End Sub

Note that adding acForm, Me.Name to DoCmd.Close will ensure that the correct
form closes, not something else that happens to have got the focus at that
time (like the new form you just opened!)
 
S

SylvieB

Hi Graham
thank you so much. It's working great. You're the best.

Graham Mandeno said:
Hi Sylvie

Use an If statement to test the value of the combo box:

Private Sub txtClosedReason_AfterUpdate()
Dim strWhere As String
If txtClosedReason = <the option to chain> Then
strWhere = "ID= " & Me.ID
DoCmd.OpenForm "opportunities details", whereCondition:=strWhere
End If
DoCmd.Close acForm, Me.Name
End Sub

Note that adding acForm, Me.Name to DoCmd.Close will ensure that the correct
form closes, not something else that happens to have got the focus at that
time (like the new form you just opened!)
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


SylvieB said:
Hello
I have a combo box with a drop down of 4 items. Right now, if I select any
of them, the form closes and pass on the data to another form , the only
problem is this should happen only if Item 1 is seIected. If item 2,3 and
4
are selected, it should just close the form. I don't know how to filter
it.
Any ideas?
Here is the code I wrote:

Private Sub txtClosedReason_AfterUpdate()
Dim strWhere As String
strWhere = "ID= " & Me.ID
DoCmd.Close
DoCmd.OpenForm "opportunities details", whereCondition:=strWhere
End Sub

Thank you for any help.
 

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