Some help manipulating search results.

Milothicus

Registered User.
Local time
Today, 16:49
Joined
Sep 24, 2004
Messages
134
I'm using this code to bring up a selected record from search results:

Private Sub listbox_Click()
On Error GoTo Err_listbox_Click

Dim stDocName As String
Dim rst As Recordset, strCriteria As String
stDocName = "editform"

strCriteria = "[field]=" & "'" & Me![listbox] & "'"
DoCmd.OpenForm stDocName

Set rst = Forms!editform.RecordsetClone
rst.FindFirst strCriteria
Forms!editform.Bookmark = rst.Bookmark
Me!listbox = ""

Exit_listbox_Click:
Exit Sub

Err_listbox_Click:
MsgBox Err.Description
Resume Exit_listbox_Click

End Sub

**Note**

*Substitute listbox for the name of your listbox
*Substitute editform for the name of the form that will contain the particular case you wish to view and edit
*Substitute field for the name of the field which you have done your search by. i.e. lastname

I got it from here.
It works fine, but only if you're opening a new form. my search form is on a tab. I'd like it to go to another tab that's already open and go to the selected record. I think i'm close to having it working, but i'm not sure what to put in the green quotes. the name of the main form is Enquiry, the name of the subform is Input, i'm not sure what the tab control name is, but i can get that if necessary. how do i name the subform in this case?
 
Update: here's my current code.

Private Sub lstSrchRslts_Click()
On Error GoTo Err_lstSrchRslts_Click
Dim stDocName As String
Dim rst As Recordset, strCriteria As String
strCriteria = "[Enquiry_Number]=" & "'" & Me![lstSrchRslts] & "'"
DoCmd.GoToPage (1)
Set rst = Forms.Enquiry!Input.RecordsetClone

rst.FindFirst strCriteria
Forms.Enquiry!Input.Bookmark = rst.Bookmark
Me!lstSrchRslts = ""
Exit_lstSrchRslts_Click:
Exit Sub
Err_lstSrchRslts_Click:
MsgBox Err.Description
Resume Exit_lstSrchRslts_Click
End Sub

It works until at least the break in the middle. it used to have an error with my recordsetclone line, but i fixed it. now i get a new error: "Object doesn't support this property or method".
 
Got it:

On Error GoTo Err_lstSrchRslts_Click
Dim stDocName As String
Dim rst As Recordset, strCriteria As String
strCriteria = "[Enquiry_Number]=" & "'" & Me![lstSrchRslts] & "'"
Set rst = Forms.Enquiry!Input.Form.RecordsetClone
rst.FindFirst strCriteria
Forms.Enquiry!Input.Form.Bookmark = rst.Bookmark
Me!lstSrchRslts = ""
Exit_lstSrchRslts_Click:
Exit Sub
Err_lstSrchRslts_Click:
MsgBox Err.Description
Resume Exit_lstSrchRslts_Click
 
Last edited:

Users who are viewing this thread

Back
Top Bottom