A
Anne
I have a form with two option groups, a list box and a bunch of text boxes.
I have two AfterUpdate event procedures - one populates the listbox based on
the option groups - opt_Date_AfterUpdate - and one finds the record you pick
on the listbox -lst_Deviation_AfterUpdate. The option groups are meant to
filter for status of a deviation and for various date information.
All is well with the listbox procedure, until I run the option group
procedure, in which case, my listbox value (in the lst_Deviation_AfterUpdate
procedure) becomes one of the option group *description* values (not their
numerical value), and I get run-time error '3077'.
I appreciate any help you can provide. I'm really learning as I go, and my
knowledge is spotty at best. You may recognize code I swiped directly from
posts in this forum! Thanks in advance.
Private Sub lst_Deviation_AfterUpdate()
Dim rs As Object
Me.txt_DeviationCount.Value = Me.lst_Deviation.ListCount
Set rs = Me.RecordsetClone
With rs
.FindFirst "DevID = " & Me.lst_Deviation
If .NoMatch Then
MsgBox "Something is wrong! This should have worked"
Else
Me.Bookmark = rs.Bookmark
End If
End With
rs.Close
Set rs = Nothing
End Sub
----------------------------------------------------
Private Sub opt_Date_AfterUpdate()
Dim mySQL As String
Dim myStatus As String
Dim myDate As String
Dim myCriteria As String
mySQL = "SELECT DISTINCTROW tbl_Deviations.Status,
tbl_Deviations.DevNum, tbl_Deviations.DevRecDate, " & _
"tbl_Deviations.TrackAssignDate, tbl_Deviations.DevDate,
tbl_Deviations.CompletedDate, tbl_Deviations.FirstReviewDate, " & _
"tbl_Deviations.FinalReviewDate, tbl_Deviations.SOPNum,
tbl_SOPs.SOPTitle, tbl_Deviations.Section, tbl_Deviations.Version, " & _
"tbl_Deviations.Intended, tbl_Deviations.Owner,
tbl_Deviations.Global, tbl_Deviations.Study, tbl_Deviations.Description, " & _
"tbl_Deviations.RootCause, tbl_Deviations.CorrectiveAction,
tbl_Deviations.ActionDeadline, tbl_Deviations.SCReviewed, " & _
"tbl_Deviations.SCReviewDate, tbl_Deviations.ReviseSOP,
tbl_Deviations.BRC " & _
"FROM tbl_SOPs RIGHT JOIN tbl_Deviations ON tbl_SOPs.SOP =
tbl_Deviations.SOPNum "
Select Case opt_Status
Case 1 'All Deviations
myStatus = ""
Case 2 'Tracking Number Assigned
myStatus = "((tbl_Deviations.Status)=""Tracking Number
Assigned"")"
Case 3 'Authorized and Closed
myStatus = "((tbl_Deviations.Status)=""Authorized And Closed"")"
Case 4 'Authorized with Action Items
myStatus = "((tbl_Deviations.Status)=""Authorized with Action
Items"")"
Case 5 'Void
myStatus = "((tbl_Deviations.Status)=""Void"")"
End Select
Select Case opt_Date
Case 1 'All Dates
myDate = ""
Case 2 'Deviation Receive Date
myDate = "DevRecDate >= #" & Me.txt_StartDate & "# And
DevRecDate <= #" & Me.txt_EndDate & "#"
Case 3 'Tracking Number Assigned Date
myDate = "TrackAssignDate >= #" & Me.txt_StartDate & "# And
TrackAssignDate <= #" & Me.txt_EndDate & "#"
Case 4 'Deviation Occured Date
myDate = "DevDate >= #" & Me.txt_StartDate & "# And DevDate <=
#" & Me.txt_EndDate & "#"
Case 5 'Completion Date
myDate = "CompletedDate >= #" & Me.txt_StartDate & "# And
CompletedDate <= #" & Me.txt_EndDate & "#"
Case 6 'Action Item Estimated Date
myDate = "ActionDeadline >= #" & Me.txt_StartDate & "# And
ActionDeadline <= #" & Me.txt_EndDate & "#"
Case 7 'Steering Committee Review Date
myDate = "SCReviewDate >= #" & Me.txt_StartDate & "# And
SCReviewDate <= #" & Me.txt_EndDate & "#"
End Select
If opt_Status = 1 And opt_Date = 1 Then myCriteria = ""
If opt_Status = 1 And opt_Date <> 1 Then myCriteria = " WHERE " & myDate
If opt_Status <> 1 And opt_Date = 1 Then myCriteria = " WHERE " & myStatus
If opt_Status <> 1 And opt_Date <> 1 Then myCriteria = " WHERE " &
myStatus & " AND " & myDate
mySQL = mySQL & " " & myCriteria
mySQL = mySQL & " ORDER BY tbl_Deviations.DevNum DESC;"
Me.lst_Deviation.RowSource = mySQL
Me.txt_DeviationCount.Value = Me.lst_Deviation.ListCount
End Sub
I have two AfterUpdate event procedures - one populates the listbox based on
the option groups - opt_Date_AfterUpdate - and one finds the record you pick
on the listbox -lst_Deviation_AfterUpdate. The option groups are meant to
filter for status of a deviation and for various date information.
All is well with the listbox procedure, until I run the option group
procedure, in which case, my listbox value (in the lst_Deviation_AfterUpdate
procedure) becomes one of the option group *description* values (not their
numerical value), and I get run-time error '3077'.
I appreciate any help you can provide. I'm really learning as I go, and my
knowledge is spotty at best. You may recognize code I swiped directly from
posts in this forum! Thanks in advance.
Private Sub lst_Deviation_AfterUpdate()
Dim rs As Object
Me.txt_DeviationCount.Value = Me.lst_Deviation.ListCount
Set rs = Me.RecordsetClone
With rs
.FindFirst "DevID = " & Me.lst_Deviation
If .NoMatch Then
MsgBox "Something is wrong! This should have worked"
Else
Me.Bookmark = rs.Bookmark
End If
End With
rs.Close
Set rs = Nothing
End Sub
----------------------------------------------------
Private Sub opt_Date_AfterUpdate()
Dim mySQL As String
Dim myStatus As String
Dim myDate As String
Dim myCriteria As String
mySQL = "SELECT DISTINCTROW tbl_Deviations.Status,
tbl_Deviations.DevNum, tbl_Deviations.DevRecDate, " & _
"tbl_Deviations.TrackAssignDate, tbl_Deviations.DevDate,
tbl_Deviations.CompletedDate, tbl_Deviations.FirstReviewDate, " & _
"tbl_Deviations.FinalReviewDate, tbl_Deviations.SOPNum,
tbl_SOPs.SOPTitle, tbl_Deviations.Section, tbl_Deviations.Version, " & _
"tbl_Deviations.Intended, tbl_Deviations.Owner,
tbl_Deviations.Global, tbl_Deviations.Study, tbl_Deviations.Description, " & _
"tbl_Deviations.RootCause, tbl_Deviations.CorrectiveAction,
tbl_Deviations.ActionDeadline, tbl_Deviations.SCReviewed, " & _
"tbl_Deviations.SCReviewDate, tbl_Deviations.ReviseSOP,
tbl_Deviations.BRC " & _
"FROM tbl_SOPs RIGHT JOIN tbl_Deviations ON tbl_SOPs.SOP =
tbl_Deviations.SOPNum "
Select Case opt_Status
Case 1 'All Deviations
myStatus = ""
Case 2 'Tracking Number Assigned
myStatus = "((tbl_Deviations.Status)=""Tracking Number
Assigned"")"
Case 3 'Authorized and Closed
myStatus = "((tbl_Deviations.Status)=""Authorized And Closed"")"
Case 4 'Authorized with Action Items
myStatus = "((tbl_Deviations.Status)=""Authorized with Action
Items"")"
Case 5 'Void
myStatus = "((tbl_Deviations.Status)=""Void"")"
End Select
Select Case opt_Date
Case 1 'All Dates
myDate = ""
Case 2 'Deviation Receive Date
myDate = "DevRecDate >= #" & Me.txt_StartDate & "# And
DevRecDate <= #" & Me.txt_EndDate & "#"
Case 3 'Tracking Number Assigned Date
myDate = "TrackAssignDate >= #" & Me.txt_StartDate & "# And
TrackAssignDate <= #" & Me.txt_EndDate & "#"
Case 4 'Deviation Occured Date
myDate = "DevDate >= #" & Me.txt_StartDate & "# And DevDate <=
#" & Me.txt_EndDate & "#"
Case 5 'Completion Date
myDate = "CompletedDate >= #" & Me.txt_StartDate & "# And
CompletedDate <= #" & Me.txt_EndDate & "#"
Case 6 'Action Item Estimated Date
myDate = "ActionDeadline >= #" & Me.txt_StartDate & "# And
ActionDeadline <= #" & Me.txt_EndDate & "#"
Case 7 'Steering Committee Review Date
myDate = "SCReviewDate >= #" & Me.txt_StartDate & "# And
SCReviewDate <= #" & Me.txt_EndDate & "#"
End Select
If opt_Status = 1 And opt_Date = 1 Then myCriteria = ""
If opt_Status = 1 And opt_Date <> 1 Then myCriteria = " WHERE " & myDate
If opt_Status <> 1 And opt_Date = 1 Then myCriteria = " WHERE " & myStatus
If opt_Status <> 1 And opt_Date <> 1 Then myCriteria = " WHERE " &
myStatus & " AND " & myDate
mySQL = mySQL & " " & myCriteria
mySQL = mySQL & " ORDER BY tbl_Deviations.DevNum DESC;"
Me.lst_Deviation.RowSource = mySQL
Me.txt_DeviationCount.Value = Me.lst_Deviation.ListCount
End Sub