Pop up form/Required Fields

no, just make sure you're in the unload event; and when code breaks, enter the code I gave you in the immediate window.
 
and to make sure i did wut i was suppose to, cuz im not completely sure what the term "unload event" is but I entered some data, closed the pop up form and then my code page came up and i entered that expression and got -1. hope i did that right.
 
-1 mean it is true.

You are, in fact, on a entirely different record when the unload event load.

Cut the code and past it into the BeforeUpdate event then it should work correctly.

I know that missingling's mockup worked, but I can only assume that you have it set up a bit differently that it's moving to new record somehow.
 
Thank god it works!!! Thank you so much. One minor problem, it prompts me once i leave out a field "you are missing bla bla. are you sure you want to cancel? if you do the info will not be added" which is fine, but if i say NO i dont want to cancel, it still closes out the form
 
You need to add

Cancel = True

to the part that processes the message box response of NO.
 
If blnError Then
strError = Left(strError, Len(strError) - 1)
///Cancel = True///
If MsgBox(strError & vbCrLf & "Are you sure you want to cancel." & vbCrLf & "If you do, the info will not be added.", vbQuestion + vbYesNo, "Close Confirmation") = vbNo Then
Cancel = True

I put it in there, but i dont think i follow becuz that didnt work....
 
Last edited:
I get the message saying i missed so and so fields...are you sure u want to cancel. if you do the info wont be added.

So that works...but to answer that message box, when i say Yes-it will exit out of the form w/o saving...that works.

When i hit No (aka, dont cancel) it still closes out the form instead of letting me return to the input screen to add w/e field im missing..

I dont kno how to change the code around for it not to do that
 
Ah, I think I understand now.

What is happening is that you have a button that tells the form to close when it's clicked. To see what it does, put in a breakpoint in button's click then F8 all way through. I'd bet this is what going to happen.

In button's OnClick, the execution moves to the line where form will be closed.

The BeforeUpdate event then fires and takes the execution to the code within BeforeUpdate event, and give you the prompt. You say "No", so the BeforeUpdate fails (e.g. no records is being saved). The execution then returns to the the button's OnClick event and complete the closing of form.

Therefore, you need to have something to tell form to close *only* if it is allowed to.

How exactly to implement this, would depend on how your OnClick event is coded. Maybe if you paste this, we can give some specific suggestions (I have some idea but didn't want to give you wrong one so...)
 
I dont have any onclick code for that. I just have macros that open and close the form.

well close the pop up form and open another form, like a back button
 
You can convert macros into code....

Tools -> Macros -> Convert to Visual Basic.
 
Theres 2 on this form:

Private Sub Command16_Click()
On Error GoTo Err_Command16_Click

Dim stDocName As String

stDocName = "back from popdept to contract input"
DoCmd.RunMacro stDocName

Exit_Command16_Click:
Exit Sub

Err_Command16_Click:
MsgBox Err.Description
Resume Exit_Command16_Click

End Sub

--------------------------------------------------

Private Sub Command17_Click()
On Error GoTo Err_Command17_Click

Dim stDocName As String

stDocName = "back from pop up to dash"
DoCmd.RunMacro stDocName

Exit_Command17_Click:
Exit Sub

Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click

End Sub
 
Okay.

I honestly have no idea what they are supposed to do. I've never used macros.

If you go to design view, and you select the close button, look at the properties window, under "Other" tab, there's Name... what is it called. It should be either Command16 or Command17
 
Macros are just buttons to help get around the database.

But yea, the 2 names are the ones you listed. Each one brings you to a different spot on the database...
 
Can you post the db (or stripped down version)? I'd like to actually "see" what is going on.
 
Here is a stripped down version of my DB

Here is a stripped down version of my database. The form "frmPopupDept" is the one I'm having trouble with.
 

Attachments

You just need to add

Me.Undo

after the Cancel = True code.
 

Users who are viewing this thread

Back
Top Bottom