I have a simple form. When I load it, it displays an old search result, i.e. Lastname Smith. I am not sure what I am not doing right.
The form is in two parts: the search form and the data entry (results) form.
Here is the code for the Results:
Option Compare Database
Private Sub cmdAll_Click()
Dim LSQL As String
'Clear criteria
GCriteria = ""
'Display all Doctors
LSQL = "select * from List"
Form_frmDoctors.RecordSource = LSQL
Form_frmDoctors.Caption = "Doctors (All doctors)"
End Sub
Private Sub cmdReport_Click()
'Open report
DoCmd.OpenReport "rptDoctors", acViewPreview, , GCriteria
End Sub
Private Sub cmdSearch_Click()
DoCmd.OpenForm "frmSearch", , , , , acDialog
End Sub
Private Sub DELETER_Click()
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Sub
Private Sub Form_Open(Cancel As Integer)
'Clear criteria when form is first opened
GCriteria = ""
End Sub
Private Sub Save_Click()
DoCmd.Save
End Sub
Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Exit_Next_Record_Click:
Exit Sub
Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click
End Sub
Private Sub Prev_Doctor_Click()
On Error GoTo Err_Prev_Doctor_Click
DoCmd.GoToRecord , , acPrevious
Exit_Prev_Doctor_Click:
Exit Sub
Err_Prev_Doctor_Click:
MsgBox Err.Description
Resume Exit_Prev_Doctor_Click
End Sub
Here is the code for the search:
Option Compare Database
Private Sub cmdClose_Click()
'Close form
DoCmd.Close
End Sub
Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."
ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmDoctors based on search criteria
Form_frmDoctors.RecordSource = "select * from List where " & GCriteria
Form_frmDoctors.Caption = "List (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
End If
End Sub
Also, I would like to add a text box that shows the total number of records - same thing that you would see in the navigation bar, but without the current record number.
Thanks.
The form is in two parts: the search form and the data entry (results) form.
Here is the code for the Results:
Option Compare Database
Private Sub cmdAll_Click()
Dim LSQL As String
'Clear criteria
GCriteria = ""
'Display all Doctors
LSQL = "select * from List"
Form_frmDoctors.RecordSource = LSQL
Form_frmDoctors.Caption = "Doctors (All doctors)"
End Sub
Private Sub cmdReport_Click()
'Open report
DoCmd.OpenReport "rptDoctors", acViewPreview, , GCriteria
End Sub
Private Sub cmdSearch_Click()
DoCmd.OpenForm "frmSearch", , , , , acDialog
End Sub
Private Sub DELETER_Click()
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End Sub
Private Sub Form_Open(Cancel As Integer)
'Clear criteria when form is first opened
GCriteria = ""
End Sub
Private Sub Save_Click()
DoCmd.Save
End Sub
Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Exit_Next_Record_Click:
Exit Sub
Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click
End Sub
Private Sub Prev_Doctor_Click()
On Error GoTo Err_Prev_Doctor_Click
DoCmd.GoToRecord , , acPrevious
Exit_Prev_Doctor_Click:
Exit Sub
Err_Prev_Doctor_Click:
MsgBox Err.Description
Resume Exit_Prev_Doctor_Click
End Sub
Here is the code for the search:
Option Compare Database
Private Sub cmdClose_Click()
'Close form
DoCmd.Close
End Sub
Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."
ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmDoctors based on search criteria
Form_frmDoctors.RecordSource = "select * from List where " & GCriteria
Form_frmDoctors.Caption = "List (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
End If
End Sub
Also, I would like to add a text box that shows the total number of records - same thing that you would see in the navigation bar, but without the current record number.
Thanks.