Private Sub txtFind_AfterUpdate()
Dim d As DAO.Database, q As DAO.QueryDef, sql As String, sQuery As String
Dim strConnect As String
Dim strTextdata As String
strConnect = "ODBC;DSN=CompanyDSN;UID=ralph;DATABASE=companydb1;Trusted_Connection=Yes"
Set d = CurrentDb
sQuery = "tmpQuery"
On Error Resume Next
DoCmd.DeleteObject acQuery, sQuery
On Error GoTo errH
Set q = d.CreateQueryDef(sQuery, sql)
q.Connect = strConnect
strTextdata = Me!txtFIND.Value
q.sql = "Select ID From tblCompany Where [Identifier] = '" & strTextdata & "'"
q.Close
Set d = Nothing
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSQL_Finder_Search_Result"
DoCmd.OpenForm stDocName, , , stLinkCriteria
If DCount("*", "tmpQuery") = 0 Then
DoCmd.Close acForm, "frmSQL_Finder_Search_Result"
MsgBox "No matches found!", vbExclamation, "No matches!"
Exit Sub
End If
Forms!CompanyForm.RecordsetClone.FindFirst "[ID] = " & Forms!frmSQL_Finder_Search_Result![txtID]
Forms!CompanyForm.Bookmark = Forms!CompanyForm.RecordsetClone.Bookmark
DoCmd.Close acForm, "frmSQL_Finder_Search"
If DCount("*", "tmpQuery") = 1 Then
DoCmd.Close acForm, "frmSQL_Finder_Search_Result"
End If
Exit Sub
errH:
MsgBox Err & " " & Err.Description
End Sub
|