If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Displaying a message box and closing a form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-10, 09:02
Lurcio Lurcio is offline
Registered User
 
Join Date: Sep 2010
Posts: 13
Displaying a message box and closing a form

Hi,

I have two forms, in the first form the user enters data into a text box, I then have a button that opens another form, this form is linked to a query and finds the record based on what the user has entered into the text.

I'm trying to add in some code so when no record is returned a message box appears and the form closes automatically. When there is no record then my primary key on the second form automatically becomes "0".

In the form load section of the second form I have the following:

If VoucherNo = 0 Then
MsgBox "There is no record to show"
DoCmd.Close
End If


It only seems to half work. The message box appears but when I click Ok on the message box the form loads up instead of closing down.

Where am I going wrong?
Reply With Quote
  #2 (permalink)  
Old 11-15-10, 09:13
canupus canupus is offline
Registered User
 
Join Date: Jul 2004
Location: South Dakota
Posts: 242
Have you tried checking to see if any records exist before opening the second form?

So in the first form when the button is clicked, check to see if a record exists and if it does open the second form. Otherwise, just set your text box to 0.

C
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On