Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error message doesn't work as desired

Status
Not open for further replies.

cammi

Programmer
May 3, 2001
13
US
I have a subform that pops up and contains listboxes for a selection of records that meet certain criteria in an Access 2000 db. An option from each list box must be selected to build a number that appears on the main form. However, if the user doesn't select any options or just a few, etc, they are allowed to go back to the main form.
I want a message to pop up to inform them that they will not get the desired results if they don't. I have created this error message, but when the form is tested, I can get it to display a message if they click the accept button except that the message is displayed before the subform closes and then again on the main form. If I select options as required to generate the number, I still receive the message. I cannot figure out what's going on with this.

Can anyone please help?

Private Sub Command21_Click()
'The error should check that a selection has been made in each option

If Me!QTB_CompItemID <> &quot; &quot; Then
Call BuildNumber
DoCmd.Close
Else
GoTo Error_CompItemID
Resume
End If

Error_CompItemID:
MsgBox &quot;You must make a selection for each blank field on this form to generate the 25-digit part number.&quot;

Exit_Command21_Click:
Exit Sub

End Sub
 
Put an Exit Sub statement right before Error_CompItemID:

It's running your MsgBox code once from the GoTo statement, and once again before the procedure goes out of scope.

Good luck!

-Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
It is still allowing me to exit the subform before all the options are selected. It's almost as if it thinks a selection has been made even though there is nothing displayed in the list box on the form.

It works correctly on the first row of the form, but then after the second, I am allowed to close the form. I guess this happens because it thinks since there is an entry in that field, that it doesn't matter that there are none in the rest of the rows in the form.
 
dear cammi,

If Me!QTB_CompItemID <> &quot; &quot; Then

is it suer there is a space in that id or shouldn't it be :
If Me!QTB_CompItemID <> &quot;&quot; Then

which checks if it is empty

try a debug.print &quot;b&quot; & me!qtb_compitemid & &quot;e&quot;
to see wether there is a space in or not.

regards strid
 
I'm confused. Your first thread says if the user selects no options or just a few, they are allowed to go back to the main form. Now you say it works correctly on the first row of the form, but after the second you are allowed to close the form. I thought you only wanted to display a message informing the user if they won't get the desired results, and return to the main form anyway...

The only place in the above code where the form gets unloaded is the DoCmd.Close, which only gets executed if Me!QTB_CompItemID <> &quot; &quot; (or &quot;&quot;). If it should not be unloaded, I'd look there like Sawatzky suggested.

Also, I don't think you need the Resume statement above. It should be in your error handler, if anywhere.

If you still have problems, could you respecify what it is you need to do?

Thanks!

-Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Thanks for all your help, but I think
I have figured out what is happening...

If I click in the field before making a selection, the msg appears and I cannot exit the subform (which is good). I have been just clicking the &quot;accept&quot; button and the msg pops up, but allows me to exit the form.

So I have to find out how to get the form to recognize that there may be available options after selecting the first. It needs to recognize when the user has selected the last option before clicking the &quot;accept&quot; button.

I am not sure how to do this since the number of options may vary based on the selection of the main form.
 
You know what, you're right.

I was just trying to prevent the user from exiting before all fields were selected, but as long as they know what's going on, they can fix it them selves (though for some reason, they just can't understand how to use a computer).

Thanks for all the help!

Cammi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top