I am trying to write a code so that when the user click on an account in the list box, it will search for a record in the table and dispay the record, if there is no record found, display the "No record on file " message. it works well with one account, but when I have 2 accounts in the list box, when a user click on the second account in the list box, the form display the data, but the error message still pop up saying "no record on file for the 1st account). Here is my code. Anybody has any idea?
Thanks a lot!
Dim db As Database
Dim rst As Recordset
Dim stLinkCriteria As String
'Open form and carry account number over first
stLinkCriteria = "[CVACCTNO]=" & Me![txtAcctNo]
DoCmd.OpenForm "frmIDX", , , stLinkCriteria
[Forms]![frmIDX]![txtPtName] = Me.txtPtName
'Find if record is exit. Find from beginning of recordset to ending of recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("tblIDX", dbOpenDynaset)
rst.FindFirst "[ACCTNOIDX] = " & Me![CVACCTNO] & ""
If rst.NoMatch Then
MsgBox "No IDX record was found under this account number: " & CVACCTNO & "", vbOKOnly, "No Record On File"
DoCmd.Close acForm, "frmIDX", acSaveNo
Else
stLinkCriteria = "[CVACCTNO]=" & Me![txtAcctNo]
DoCmd.OpenForm "frmIDX", , , stLinkCriteria
[Forms]![frmIDX]![txtPtName] = Me.txtPtName
End If