By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Calling another Form from a Listbox.

P: 1
I have a form that has a Listbox that when you set the Event Procedure to a "Click" or "Enter", I want to have it open a 2nd form based on what was selected in the dropdown. Does anyone have the VB code to paste in and modify for the event procedure for this?
Sep 8 '08 #1
Share this Question
Share on Google+
1 Reply


DonRayner
Expert 100+
P: 489
If you want to open the new form as soon as you select it then put your code into the controls Changet event


Private Sub MyListbox_Change()
On Error GoTo ErrPoint
Dim MyVar As String
MyVar = Me.MyListbox.Value
DoCmd.OpenForm MyVar
ExitPoint:
Exit Sub
ErrPoint:
MsgBox "Error# " & Err.Number & " " & Err.Description
Resume ExitPoint
End Sub

If you want to use another event or button to open the form, then declare the MyVar as a public variable at the top of the module right after the option statements

Option Compare Database
Option Explicit

Public MyVar as string

Then your sub would look like this

Private Sub MyListbox_Change()
On Error GoTo ErrPoint
MyVar = Me.MyListbox.Value
ExitPoint:
Exit Sub
ErrPoint:
MsgBox "Error# " & Err.Number & " " & Err.Description
Resume ExitPoint
End Sub

Finally wherever control or event is to activate the form add into it

DoCmd.OpenForm MyVar

Hope this helps
Sep 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.