G
Guest
Help! I cannot figure out this problem.
I am trying to use VBA for the first time to create a database to look after patient info. I created a form "Patient Input" which allows the input and viewing of info. I placed on the form an option group allowing the filtering of the info to the patients of one of 3 members of staff. This worked OK.
I then created anoth form "Report Filter Form" which allows the user to select a particular report and filter the info to one of the members of staff. This worked as well (eventually).
When I next tried to filter the info on the "Patient Input" form, I received a message, "Runtime error 2001 You canceled the previous operation." This happens even if I have not called the second form.
In case it is helpful, I have set out the relevant code below.
I would appreciate any help. This is driving me crazy.
Option Compare Database
Option Explicit
Dim pstrReportName As String
Dim pstrFilter As String
Behind the "Report Filter Form":-
Private Sub ExitReportFilterButton_Click()
On Error GoTo Err_ExitReportFilterButton_Click
DoCmd.Close acForm, "Report Filter Form"
Exit_ExitReportFilterButton_Click:
Exit Sub
Err_ExitReportFilterButton_Click:
MsgBox Err.Description
Resume Exit_ExitReportFilterButton_Click
End Sub
Private Sub ProceedReportButton_Click()
On Error GoTo Err_ProceedReportButton_Click
DoCmd.OpenReport pstrReportName, acViewPreview, , pstrFilter
DoCmd.Close acForm, "Report Filter Form"
Exit_ProceedReportButton_Click:
Exit Sub
Err_ProceedReportButton_Click:
MsgBox Err.Description
Resume Exit_ProceedReportButton_Click
End Sub
Private Sub ReportSelecterOption_BeforeUpdate(Cancel As Integer)
On Error Resume Next
Select Case ReportSelecterOption
Case 1
pstrReportName = "Patients (Alphabetical)"
Case 2
pstrReportName = "Patients (By Case Open for)"
Case 3
pstrReportName = "Patients (By case open to & case open for)"
Case 4
pstrReportName = "Patients by registration date"
Case 5
pstrReportName = "Patients (by case open to)"
End Select
End Sub
Private Sub ReportFilterOption_BeforeUpdate(Cancel As Integer)
On Error Resume Next
Select Case ReportFilterOption
Case 2 'KM selected
pstrFilter = "[case open to] = 2"
Case 3 'CW selected
pstrFilter = "[case open to] = 3"
Case 4 'HvL selected
pstrFilter = "[case open to] = 1"
Case 5 'Unallocated selected
pstrFilter = "[case open to] = 4"
Case Else 'no value for intFilter if All selected
pstrFilter = ""
End Select
End Sub
++++++++++++++++++++++++++++++
Behind the "Patient Input" form:
Private Sub FilterOptions_AfterUpdate()
' Apply or remove filter
Select Case FilterOptions
Case 1 'All patients
Me.FilterOn = False
Me.Combo29.Visible = True
Case 2 'Patients of KM
Me.Filter = "[Case Open to] = '2'"
Me.FilterOn = True
Me.Combo29.Visible = False
Me.Combo43.BackColor = vbYellow
Case 3 'Patients of CW
Me.Filter = "[Case Open to] = '3'"
Me.FilterOn = True
Me.Combo29.Visible = False
Case 4 'Patients of HvL
Me.Filter = "[Case Open to] = '1'"
Me.FilterOn = True
Me.Combo29.Visible = False
Case 5 'Unallocated
Me.Filter = "[Case Open to] = '4'"
Me.FilterOn = True
Me.Combo29.Visible = False
End Select
End Sub
Private Sub Form_AfterUpdate()
Forms![Patient input]![Patient Name].SetFocus
End Sub
Private Sub Combo29_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo29], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
[Patient Name].SetFocus
End Sub
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
' Set the option group value to match the user's filtering action
If applttype = acShowAllRecords Then
FilterOptions = 1 'Set the All Patients option
ElseIf Filter <> "[Case Open to] = '1'" And Filter <> "[Case Open to] = '2'" _
And Filter <> "[Case Open to] = '3'" And Filter <> "[Case Open to] = '4'" Then
FilterOptions = Null ' Don't set any option value
End If
End Sub
Private Sub Form_Close()
End Sub
Private Sub Form_Current()
Combo29 = ID ' Update the Find Record combo box.
End Sub
Private Sub PatientInputExitButton_Click()
On Error GoTo Err_PatientInputExitButton_Click
DoCmd.Close acForm, "Patient Input"
Exit_PatientInputExitButton_Click:
Exit Sub
Err_PatientInputExitButton_Click:
MsgBox Err.Description
Resume Exit_PatientInputExitButton_Click
End Sub
I am trying to use VBA for the first time to create a database to look after patient info. I created a form "Patient Input" which allows the input and viewing of info. I placed on the form an option group allowing the filtering of the info to the patients of one of 3 members of staff. This worked OK.
I then created anoth form "Report Filter Form" which allows the user to select a particular report and filter the info to one of the members of staff. This worked as well (eventually).
When I next tried to filter the info on the "Patient Input" form, I received a message, "Runtime error 2001 You canceled the previous operation." This happens even if I have not called the second form.
In case it is helpful, I have set out the relevant code below.
I would appreciate any help. This is driving me crazy.
Option Compare Database
Option Explicit
Dim pstrReportName As String
Dim pstrFilter As String
Behind the "Report Filter Form":-
Private Sub ExitReportFilterButton_Click()
On Error GoTo Err_ExitReportFilterButton_Click
DoCmd.Close acForm, "Report Filter Form"
Exit_ExitReportFilterButton_Click:
Exit Sub
Err_ExitReportFilterButton_Click:
MsgBox Err.Description
Resume Exit_ExitReportFilterButton_Click
End Sub
Private Sub ProceedReportButton_Click()
On Error GoTo Err_ProceedReportButton_Click
DoCmd.OpenReport pstrReportName, acViewPreview, , pstrFilter
DoCmd.Close acForm, "Report Filter Form"
Exit_ProceedReportButton_Click:
Exit Sub
Err_ProceedReportButton_Click:
MsgBox Err.Description
Resume Exit_ProceedReportButton_Click
End Sub
Private Sub ReportSelecterOption_BeforeUpdate(Cancel As Integer)
On Error Resume Next
Select Case ReportSelecterOption
Case 1
pstrReportName = "Patients (Alphabetical)"
Case 2
pstrReportName = "Patients (By Case Open for)"
Case 3
pstrReportName = "Patients (By case open to & case open for)"
Case 4
pstrReportName = "Patients by registration date"
Case 5
pstrReportName = "Patients (by case open to)"
End Select
End Sub
Private Sub ReportFilterOption_BeforeUpdate(Cancel As Integer)
On Error Resume Next
Select Case ReportFilterOption
Case 2 'KM selected
pstrFilter = "[case open to] = 2"
Case 3 'CW selected
pstrFilter = "[case open to] = 3"
Case 4 'HvL selected
pstrFilter = "[case open to] = 1"
Case 5 'Unallocated selected
pstrFilter = "[case open to] = 4"
Case Else 'no value for intFilter if All selected
pstrFilter = ""
End Select
End Sub
++++++++++++++++++++++++++++++
Behind the "Patient Input" form:
Private Sub FilterOptions_AfterUpdate()
' Apply or remove filter
Select Case FilterOptions
Case 1 'All patients
Me.FilterOn = False
Me.Combo29.Visible = True
Case 2 'Patients of KM
Me.Filter = "[Case Open to] = '2'"
Me.FilterOn = True
Me.Combo29.Visible = False
Me.Combo43.BackColor = vbYellow
Case 3 'Patients of CW
Me.Filter = "[Case Open to] = '3'"
Me.FilterOn = True
Me.Combo29.Visible = False
Case 4 'Patients of HvL
Me.Filter = "[Case Open to] = '1'"
Me.FilterOn = True
Me.Combo29.Visible = False
Case 5 'Unallocated
Me.Filter = "[Case Open to] = '4'"
Me.FilterOn = True
Me.Combo29.Visible = False
End Select
End Sub
Private Sub Form_AfterUpdate()
Forms![Patient input]![Patient Name].SetFocus
End Sub
Private Sub Combo29_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo29], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
[Patient Name].SetFocus
End Sub
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
' Set the option group value to match the user's filtering action
If applttype = acShowAllRecords Then
FilterOptions = 1 'Set the All Patients option
ElseIf Filter <> "[Case Open to] = '1'" And Filter <> "[Case Open to] = '2'" _
And Filter <> "[Case Open to] = '3'" And Filter <> "[Case Open to] = '4'" Then
FilterOptions = Null ' Don't set any option value
End If
End Sub
Private Sub Form_Close()
End Sub
Private Sub Form_Current()
Combo29 = ID ' Update the Find Record combo box.
End Sub
Private Sub PatientInputExitButton_Click()
On Error GoTo Err_PatientInputExitButton_Click
DoCmd.Close acForm, "Patient Input"
Exit_PatientInputExitButton_Click:
Exit Sub
Err_PatientInputExitButton_Click:
MsgBox Err.Description
Resume Exit_PatientInputExitButton_Click
End Sub