I have a bound form to a SQL Server table. On that same form I have a listbox that gets distinct loan numbers from that table. The listbox has 2 columns, the PK and the loan number. I used the following code to display the record on the bound form they selected in the listbox so that they can edit it if needed.
This was working great until all of a sudden it stopped working for no reason and I get Error 2105 "You can't go to the specified record."
What am I doing wrong?
Private Sub lst_LocalLoanNumberList_Click()
DoCmd.GoToRecord acDataForm, "frm_LocalLoanInfo", acGoTo, Me.lst_LocalLoanNumberList.Column(0)
End Sub
CodePudding user response:
Try this:
Private Sub lst_LocalLoanNumberList_Click()
Dim pk_index As Integer
pk_index = Me.lst_LocalLoanNumberList.Column(0)
With Form_frm_LocalLoanInfo.Recordset
.FindFirst "ID_name =" & pk_index
Form_frm_LocalLoanInfo.SetFocus
If .NoMatch Then
MsgBox "Not found!"
End If
End With
End Sub
Change ID_name
with your ID of the form.