syntax problem

D

David Hunt

Trying to do something simple

Docmd.OpenForm "Query"

If Query is empty then

Do X

Else

Do Y

End If

How do I write the "If Query is empty then" statement

David Hunt
 
D

Dirk Goldgar

David Hunt said:
Trying to do something simple

Docmd.OpenForm "Query"

If Query is empty then

Do X

Else

Do Y

End If

How do I write the "If Query is empty then" statement

David Hunt

Is this really a form named "Query"? It's a confusing name, but I'll
asume it's right. By "empty", I take it you mean "has no records to
display." You could use code like this:

If Forms!Query.Recordset.RecordCount = 0 Then
' the form is empty
Else
' the form is not empty
End If
 
G

Guest

I screwed that up, that's why it was confusing here is my
actual code....

DoCmd.OpenQuery "Scrub_2_Print_Blank_Account_Records",
acViewPreview, acReadOnly

If ????.Scrub_2_Print_Blank_Account_Records.Recordset.Recor
dCount = 0 Then
MsgBox "Scrub 2 is Complete",
vbInformation, "Scrub 2: Fix 'Account' Blanks"
Exit Sub
Else
DoCmd.PrintOut
DoCmd.Close
MsgBox "Retieve List of Blanks from default
Printer", vbInformation, "Scrub 2: Fix 'Account' Blanks"
DoCmd.OpenForm "Make Changes", acNormal
DoCmd.Maximize
End If


I'm using a Query not a Form. What do I use instead
of "Forms" ???

Thanks much I appreciate

David
 
D

Dirk Goldgar

I screwed that up, that's why it was confusing here is my
actual code....

DoCmd.OpenQuery "Scrub_2_Print_Blank_Account_Records",
acViewPreview, acReadOnly

If ????.Scrub_2_Print_Blank_Account_Records.Recordset.Recor
dCount = 0 Then
MsgBox "Scrub 2 is Complete",
vbInformation, "Scrub 2: Fix 'Account' Blanks"
Exit Sub
Else
DoCmd.PrintOut
DoCmd.Close
MsgBox "Retieve List of Blanks from default
Printer", vbInformation, "Scrub 2: Fix 'Account' Blanks"
DoCmd.OpenForm "Make Changes", acNormal
DoCmd.Maximize
End If


I'm using a Query not a Form. What do I use instead
of "Forms" ???

The safest way to do this is to check the query result first, before
even opening the query, and don't bother displaying it unless you have
some results. It might look like this:

'---- start of code ----
Dim strQuery As String
strQuery = "Scrub_2_Print_Blank_Account_Records"

If DCount("*", strQuery) = 0 Then
MsgBox "Scrub 2 is Complete", _
vbInformation, "Scrub 2: Fix 'Account' Blanks"
Exit Sub
Else

DoCmd.OpenQuery strQuery, acViewPreview, acReadOnly
DoCmd.PrintOut
DoCmd.Close acQuery, strQuery
MsgBox "Retieve List of Blanks from default Printer", _
vbInformation, "Scrub 2: Fix 'Account' Blanks"
DoCmd.OpenForm "Make Changes", acNormal
DoCmd.Maximize
End If

'---- end of code ----
 

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