By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Blank Form

P: n/a
I have a form based on a query. If the query returns no records the form
opens blank. How do I catch this conidtion at the form load so I can
stop it?

Michael Charney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

Hi. Look up the DCOUNT function in Access VBA Help.

Colin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #2

P: n/a


Hi. My earlier post was a little to brief. DCOUNT accepts a table or
query name and a field name as a parameter. If you wrote something like
this it should work

if DCOUNT("fieldname","queryname")= 0 then docmd.close
msbox("message to user")

if this is not clear, post back and I will help some more. do not email
as it is a spam trap.

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

P: n/a
from looking at the code I assume it would go in the Form's load section
correct?

Michael Charney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

P: n/a
I added the following to the forms load section:

Dim Response

If DCount("SumOfItemTotal","qryBidderCheckOutTotals") =0 Then

DoCmd.Close

Response = MsgBox("The bidder number is incorrect," & Chr(13) & "or the
bidder has not made any purchases" & Chr(13) & "Click Yes to try another
bidder # or No to cancel", vbYesNo, "Bidder Warning Message")

If Response = 6 Then

DoCmd.OpenForm "frmBiddercheckout"

Exit Sub

End If

End If

and I received the following error:

Run-Time Error '2001'

You Canceled the previous operation.

Michael Charney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5

P: n/a
Hi Michael. Unfortunately I am at home right now and do not have my
application in front of me. I will post another reply tomorrow when I
have looked at my code.

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6

P: n/a
Hi Michael.

sorry it has taken me so long.

here is my code in the onclick event of a button which opens the
Contacts form but only if there are contacts in the table.

--Begin Code--

Private Sub btnEditContacts_Click()
Dim Resp As Integer
If DCount("ContactID", "Contacts") = 0 Then
Resp = MsgBox("There are no contacts to edit. Do you want to add a
contact?", vbYesNo, "No data in Contacts Table")
If Resp = vbYes Then
DoCmd.Close
DoCmd.OpenForm "Contacts Form", , , , acFormAdd, acDialog
ElseIf Resp = vbNo Then
End If
ElseIf DCount("ContactID", "Contacts") > 0 Then
DoCmd.Close
DoCmd.OpenForm "Contacts Form", acNormal, , , acFormEdit, acDialog,
"E"
End If
MsgBox ("Do you want to edit anything else?"), vbYesNo, "Edit anything
else?"
If Resp = vbYes Then
DoCmd.Close
DoCmd.OpenForm "Edit Form", , , , , acDialog
ElseIf Resp = vbNo Then
End If
End Sub

--End Code--
Just change the names of the controls and the prompts
Hope this helps

Colin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #7

P: n/a
Thanks for information! It really helped me out! If you ever need
anything I could help with let me know.

Michael Charney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #8

P: n/a
so it worked for you then? The only thing I might change in your case is
to remove the "A" and the "E" after the docmd.openform lines. those are
specific to my app and I doubt you will need them. then again if it is
working as is, you should let it do its thing.

glad I could help

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.