Hi
I have a form named "frm_baptismsallParishes"
On that form I have a button which calls the form
"frm_BaptismSoundexSurnameSearchAll"
using the code
Code:
Private Sub btn_baptismSurnameSoundex_Click()
DoCmd.Close
DoCmd.OpenForm FormName:="frm_BaptismSoundexSurnameSearchAll"
End Sub
THat form contains a button which calls the form
Code:
Private Sub btn_Search_Click()
DoCmd.Close
DoCmd.OpenForm FormName:="frm_BaptismSurnameSoundexSearchResultsAll"
End Sub
The form "frm_BaptismSurnameSoundexSearchResultsAll" source is the query
"qry_BaptismsSurnameSoundexAll"
Code:
SELECT tbl_Parish.Parish, tbl_Church.Church, tbl_Baptism.FicheNo, tbl_Baptism.BirthDate, tbl_Baptism.DateOfBaptism, tbl_Baptism.YearOfBaptism, tbl_Baptism.FullDateOfBaptism, tbl_Baptism.ChildsName, tbl_Baptism.Surname, tbl_Baptism.Sex, tbl_Baptism.Parents, tbl_Baptism.Abode, tbl_Baptism.Occupation, tbl_Baptism.RefNo, tbl_Baptism.PageNo, tbl_Baptism.EntryNo, tbl_Baptism.Minister, tbl_Baptism.Notes, tbl_Baptism.BaptismID
FROM tbl_Parish INNER JOIN (tbl_Church INNER JOIN tbl_Baptism ON tbl_Church.ChurchID = tbl_Baptism.ChurchID_fk) ON tbl_Parish.ParishID = tbl_Church.ParishID_fk
WHERE (((tbl_Baptism.SurnameSDX)=Soundex([Enter a Surname])))
ORDER BY tbl_Baptism.FullDateOfBaptism;
(The soundex field value is created when the data is input using an update query.)
This sequence when run works perfectly until the query displays a null result then the database has to be closed and restarted.
So as per the suggestion I added an onload event to the form
"frm_BaptismSurnameSoundexSearchResultsAll"
Code:
'------------------------------------------------------------
' Form_Load
'
'------------------------------------------------------------
Private Sub Form_Load()
On Error GoTo Form_Load_Err
If (DCount("*", "qry_BaptismsSurnameSoundexAll") > 0) Then
DoCmd.OpenForm "frm_BaptismSurnameSoundexSearchResultsAll", acNormal, "", "", , acNormal
Else
Beep
MsgBox "No results found please try another spelling", vbOKOnly, ""
End If
Form_Load_Exit:
Exit Sub
Form_Load_Err:
MsgBox Error$
Resume Form_Load_Exit
End Sub
( I used the macro builder and then coverted it to VBA)
Initialy I just wanted to show a message box if there were no results from the query, If there were results then I wanted it to finish loading the form. In the end I want the message box to include a button to return to "frm_BaptismSoundexSurnameSearchAll" so that the enduser can start another search.
However I get an error error 2001
Is my logic wrong?
THanks
Ian