List Box Question

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

Hi All

I Want to be able to open a form that has a list box on
the lefthand side and then an information form on the
right. (Based on information selected in the list box)

I have already created an information form and have it set
out how i like it so if possible i would prefer to just
add this form to a new form with the list on the side.

I can add a list box in but they are not connectec and
cant work out how to connect them.

Cheers


Andrew
 
Hi Andrew:
I'll refer to one of my forms, with a "List57" representing the list box.

STEP 1-
Add the following code-

Private Sub List57_AfterUpdate()
' Find the record that matches the control.
Set rst = Me.Recordset.Clone
rst.FindFirst "[EmployeeID] = " & [List57].value
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
List57.SetFocus
List57.Requery
Exit Sub
End Sub

STEP 2-
Add more code!

Private Sub Form_Current()
If [EmployeeID] <> [List57].value Then
[List57].value = [EmployeeID]
End If
If Me.NewRecord = -1 Then
[List57].Requery
Me.Refresh
End If
Exit Sub
End Sub

STEP 3-
List57 properties should read like this-

List57.ControlSource should be left empty
List57.Row Source should read something like this:
SELECT [EMPLOYEES].[EmployeeID], [EMPLOYEES].[LastName] & ", " &
[EMPLOYEES].[FirstName] AS Expr1 FROM EMPLOYEES ORDER BY
[EMPLOYEES].[LastName], [EMPLOYEES].[FirstName];

STEP 4-
Your form's RecordSource property should look like this-

SELECT EMPLOYEES.* FROM EMPLOYEES ORDER BY [EMPLOYEES].[LastName];

That's it! They should now connect... If you encounter any problems, repost!

Regards,
AL
 
Hi Andrew:
I'll refer to one of my forms, with a "List57" representing the list box.

STEP 1-
Add the following code-

Private Sub List57_AfterUpdate()
' Find the record that matches the control.
Set rst = Me.Recordset.Clone
rst.FindFirst "[EmployeeID] = " & [List57].value
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
List57.SetFocus
List57.Requery
Exit Sub
End Sub

STEP 2-
Add more code!

Private Sub Form_Current()
If [EmployeeID] <> [List57].value Then
[List57].value = [EmployeeID]
End If
If Me.NewRecord = -1 Then
[List57].Requery
Me.Refresh
End If
Exit Sub
End Sub

STEP 3-
List57 properties should read like this-

List57.ControlSource should be left empty
List57.Row Source should read something like this:
SELECT [EMPLOYEES].[EmployeeID], [EMPLOYEES].[LastName] & ", " &
[EMPLOYEES].[FirstName] AS Expr1 FROM EMPLOYEES ORDER BY
[EMPLOYEES].[LastName], [EMPLOYEES].[FirstName];

STEP 4-
Your form's RecordSource property should look like this-

SELECT EMPLOYEES.* FROM EMPLOYEES ORDER BY [EMPLOYEES].[LastName];

That's it! They should now connect... If you encounter any problems, repost!

Regards,
AL
 
Back
Top