Ok, I have a current project to work through and I've hit a few rough spots. I am trying to create a list box which is called by a function and references the target control to populate the list boxes. I have used the example here to create the list box and it works fine.
This is the code for the module OpenMSelect:
This is the modified portion of the form frmMSelect from the MS example above.
My current issue as I see it is the Select Case does not catch the argument passed on through the control (a button in this case with =OpenMSelect("","lstZone") as the on-click event). The list box opens and there is data related to the first case "lstZone"(also the name of the control on the main form), although it ignores the Distinct clause and displays rows of the same data.
This is probably a very simple fix, but beyond this problem is a larger question. Once the list box populates with the correct data, how will it be returned back to the referenced control on the main form?
Thanks in advance. I have learned a great deal from these forums just as a lurker.
This is the code for the module OpenMSelect:
Code:
Function OpenMSelect(ByVal strsubform As String, Optional strcontrol As String)
On Error Resume Next
'test to see if anything was sent
If (strsubform & "" = "") Then
'no subform name sent
If Not IsMissing(strcontrol) Then
Forms(Screen.ActiveForm.Name)(strcontrol).SetFocus
End If
DoCmd.OpenForm "frmMSelect"
Else
'subform name sent
If Not IsMissing(strcontrol) Then
Forms(Screen.ActiveForm.Name)(strsubform).SetFocus
Forms(Screen.ActiveForm.Name)(strsubform).Form(strcontrol).SetFocus
End If
DoCmd.OpenForm "frmMSelect", , , , , , strsubform
End If
This is the modified portion of the form frmMSelect from the MS example above.
Code:
Dim vdr As Variant
Dim sFrm As String, sCtl As String
-------------------------------
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String, strItem As String
Select Case sCtl
Case lstZone
strSQL = "SELECT Distinct tblZone.Zone, tblZone.Description FROM tblZone ORDER BY tblZone.Zone"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
strItem = rs.Fields("Zone").Value & ";" & rs.Fields("Description").Value
Case lstfare
strSQL = "SELECT DISTINCT [tblPax_Fare-Types].Passenger_Type FROM [tblPax_Fare-Types]"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
strItem = rs.Fields("Passenger_Type").Value
End Select
Do Until rs.EOF
Me.List1.AddItem strItem ' Row Source Type must be Value List
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
My current issue as I see it is the Select Case does not catch the argument passed on through the control (a button in this case with =OpenMSelect("","lstZone") as the on-click event). The list box opens and there is data related to the first case "lstZone"(also the name of the control on the main form), although it ignores the Distinct clause and displays rows of the same data.
This is probably a very simple fix, but beyond this problem is a larger question. Once the list box populates with the correct data, how will it be returned back to the referenced control on the main form?
Thanks in advance. I have learned a great deal from these forums just as a lurker.