Lookup form

D

Dorian Chalom

Im trying to create a form that has two combo boxes that filter down the
records the user can view and edit. The first combo box selects the table
and the second onme selects the field. The table the information is stored
in looks like this:

Table
Field
Value

I cannot seem to get the filter to work correctly.

Can someone help?

Dorian

Private Sub cmbTable_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

On Error GoTo cmbTable_AfterUpdate_Err

Set rs = Me.Recordset.Clone

rs.FindFirst "
= '" & Me.cmbTable & "'"
'If Not rs.EOF Then
rs.Edit
Me.Bookmark = rs.Bookmark

Me.cmbField.Value = rs.Field
'End If


Me.cmbField.RowSourceType = "Table/Query"
Me.cmbField.RowSource = "SELECT DISTINCT Field FROM " & rs.Name & "
WHERE Table = '" & Me.cmbTable & "'"

Me.Filter = "
= '" & Me.cmbTable & "'"
Me.FilterOn = True

Me.cmbField.Requery
Me.Refresh

'Me.Requery

'pCBSetupPreviewReport m, m.cmbSchlID, m.cmbYear

cmbTable_AfterUpdate_Exit:
Exit Sub

cmbTable_AfterUpdate_Err:
MsgBox Err.Description
Resume cmbTable_AfterUpdate_Exit

End Sub

Private Sub cmbField_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

On Error GoTo cmbField_AfterUpdate_Err

Set rs = Me.Recordset.Clone

rs.FindFirst "[Field] = '" & Me![cmbField] & "'"
'If Not rs.NoMatch Then
rs.Edit
Me.Bookmark = rs.Bookmark
'End If

Me.Filter = "
= '" & Me.cmbTable & "' AND [Field] = '" &
Me.cmbField & "'"
Me.FilterOn = True

Me.Refresh

cmbField_AfterUpdate_Exit:
Exit Sub

cmbField_AfterUpdate_Err:
MsgBox Err.Description
Resume cmbField_AfterUpdate_Exit

End Sub
 

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

Similar Threads

Lookup Table Editor 1
How to update control 3
Add a Duplicate Record 5
Search button on form 2
Pkey Search not working 4
Combo box to find a record in Access 2007 1
Combo error 1
error on form1/form2 lookup 4

Top