View Single Post
  #1 (permalink)  
Old 09-01-10, 18:34
iramalvarez iramalvarez is offline
Registered User
 
Join Date: Sep 2010
Location: California
Posts: 15
Question Need VBA to open forms with specific queries based upon a list box

Hello,

A developer on a different form started to help me with the below vba, but no further response. I am having trouble getting it to work.
Basically I have a 3 column list box on a form called "NavPageCaseStatusListBox1" and I have a command button with the below vba. I need the below vba to open the form name in the list box and change the Record Source of that form to the query name in the list box. I will eventually have many records in the List Box and need to fix this.

Option Compare Database
Option Explicit

Private Sub CaseStatus1_Click()
With Me.NavPageCaseStatusListBox1

If .ListIndex < 0 Then
MsgBox "Please Choose a Case Status and/or Team"
Else
'0 = Status Description
'1 = FormName
'2 = QueryName

If CurrentProject.AllForms(.Column(1, .ListIndex)).IsLoaded Then
Forms(.Column(1, .ListIndex)).RecordSource = .Column(2, .ListIndex)
Else
DoCmd.OpenForm .Column(1, .ListIndex), acNormal, .Column(2, .ListIndex)
End If
End If
End With
End Sub

When I select a row in the list box that has a description, FormName and Queryname and i click on the "CaseStatus1" button that runs the above vba, a form opens but it opens the wrong form and doesn't put in the Queryname into the "Record Source" of that form. It is actually opening the form above of my selection and NOT putting in the Record Source. How do I get it to select the corresponding form AND put the queryname into the record source?

Should I have 0 or 1 for the "Bound Column" on the "NavPageCaseStatusListBox1" List Box or should I change the VBA? If so how should I change it?

Your help is greatly appreciated.

Iram/mcp
Reply With Quote