Query Returns No Records

G

Guest

I have a form with a query as a record source. I am trying to figure out how
to evaluate if the query returns any records or zero records. I have
included by failed attempts. The first IF statement is what I am having
problems with. What logic can I use to determine zero records returned from
source query?
'*********** Form on OPEN event **********
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

'If Len(Me.frm_Verify_No_In_Status.SourceObject) = 0 Then
'If Me.RecordSourceQualifier = 0 Then

If IsNull(Me.Test_Case_Path) Then
MsgBox "All Test Cases Are Available"

DoCmd.Close acForm, Me.Name

DoCmd.SetWarnings False

DoCmd.OpenQuery "qry_Add_Test_Cases"
DoCmd.OpenQuery "qry_Check_In_New"
DoCmd.OpenQuery "qry_Add_Test_Cases_History"
DoCmd.OpenQuery "qry_Check_In_New_History"

DoCmd.Close acForm, Me.Name
Forms!frm_Input_Test_Case.frm_Status.Requery

DoCmd.SetWarnings True


Else
MsgBox "You have attempted to " & Me.Status & " test cases that are
already " & Me.Status
Exit Sub

End If

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open


End Sub
 
G

Guest

Please disregard,
I found the code that works..

If Me.RecordsetClone.RecordCount = 0 Then ...

Thank you for viewing.
 
M

Marshall Barton

David said:
I have a form with a query as a record source. I am trying to figure out how
to evaluate if the query returns any records or zero records. I have
included by failed attempts. The first IF statement is what I am having
problems with. What logic can I use to determine zero records returned from
source query?
'*********** Form on OPEN event **********
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

'If Len(Me.frm_Verify_No_In_Status.SourceObject) = 0 Then
'If Me.RecordSourceQualifier = 0 Then

If IsNull(Me.Test_Case_Path) Then
MsgBox "All Test Cases Are Available"

DoCmd.Close acForm, Me.Name

DoCmd.SetWarnings False

DoCmd.OpenQuery "qry_Add_Test_Cases"
DoCmd.OpenQuery "qry_Check_In_New"
DoCmd.OpenQuery "qry_Add_Test_Cases_History"
DoCmd.OpenQuery "qry_Check_In_New_History"

DoCmd.Close acForm, Me.Name
Forms!frm_Input_Test_Case.frm_Status.Requery

DoCmd.SetWarnings True


Else
MsgBox "You have attempted to " & Me.Status & " test cases that are
already " & Me.Status
Exit Sub

End If

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End Sub


I can't make sense of that code, especially the multiple
Close statements.

But to answer your question about determining if the form
has any records:

If Me.RecordsetClone.RecordCount > 0 Then
'there is at least one record
Else
'no records
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top