G
Guest
I have a form that prompts user for entry of primary key locator field
information, upon entry (on update) form runs macro that performs select,
then open other form in update mode.
Other form that is opened is form/sub form combo. This process dies on the
following code:
Function RecordsInTable(Tablename As String, Fieldname As String) As Long
Dim strSQL As String, strTableField As String
Dim rst As DAO.Recordset
strTableField = Tablename & "." & Fieldname
strTableYr = Tablename & ".CASE_NUM_YR"
strTableCase = Tablename & ".CASE_NUM"
strFormYear = Me.txt_CASE_NUM_YR
strFormCase = Me.txt_CASE_NUM
'If strFormYear is Null, then get Case Year from Previous Case Year field
If IsNull(strFormYear) = True Then
strFormYear = Me.unbtxt_PREV_CASE_NUM_YR
End If
'If strFormCase is Null, then get Case # from Previous Case Number Field
If IsNull(strFormCase) = True Then
strFormCase = Me.unbtxt_PREV_CASE_NUM
End If
strSQL = "SELECT Count(" & strTableField & ") AS [Count] From " &
Tablename & _
" WHERE " & strTableYr & " = " & strFormYear & _
" AND " & strTableCase & " = " & strFormCase & ";"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot) '<=== dies
here
RecordsInTable = rst!Count
Set rst = Nothing
End Function
This function is called by the Sub-form during On Form Current and
Before-Update events.
Can someone assist me in placing the proper code to prevent failure on no
matching records found for the query that first runs and passes recordset to
update program.
I want to just send message back to user, incorrect infomation entered, etc,
rather than display the form and cause the form to die. I would like to
return to the first form, FR_Search_By_Case form whick prompts user for key
information.
Thanks
information, upon entry (on update) form runs macro that performs select,
then open other form in update mode.
Other form that is opened is form/sub form combo. This process dies on the
following code:
Function RecordsInTable(Tablename As String, Fieldname As String) As Long
Dim strSQL As String, strTableField As String
Dim rst As DAO.Recordset
strTableField = Tablename & "." & Fieldname
strTableYr = Tablename & ".CASE_NUM_YR"
strTableCase = Tablename & ".CASE_NUM"
strFormYear = Me.txt_CASE_NUM_YR
strFormCase = Me.txt_CASE_NUM
'If strFormYear is Null, then get Case Year from Previous Case Year field
If IsNull(strFormYear) = True Then
strFormYear = Me.unbtxt_PREV_CASE_NUM_YR
End If
'If strFormCase is Null, then get Case # from Previous Case Number Field
If IsNull(strFormCase) = True Then
strFormCase = Me.unbtxt_PREV_CASE_NUM
End If
strSQL = "SELECT Count(" & strTableField & ") AS [Count] From " &
Tablename & _
" WHERE " & strTableYr & " = " & strFormYear & _
" AND " & strTableCase & " = " & strFormCase & ";"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot) '<=== dies
here
RecordsInTable = rst!Count
Set rst = Nothing
End Function
This function is called by the Sub-form during On Form Current and
Before-Update events.
Can someone assist me in placing the proper code to prevent failure on no
matching records found for the query that first runs and passes recordset to
update program.
I want to just send message back to user, incorrect infomation entered, etc,
rather than display the form and cause the form to die. I would like to
return to the first form, FR_Search_By_Case form whick prompts user for key
information.
Thanks