Close Button Question

MuskokaMad

Registered User.
Local time
Today, 03:20
Joined
Feb 28, 2010
Messages
29
Here I thought I understood this command...

Thanks again for your help.

In my database I want to move the user through forms passing some information along and closing the previous form.

As an example I have a Form frm_NewCustomerEntry with a button cmdNewOrder that has in its OnClick Event:

Private Sub cmdNewOrder_Click()

DoCmd.OpenForm "frm_NewOrderEntry2", acNormal, , , acFormAdd
Forms!frm_NewOrderEntry2.cboCustomer = Me.ID
Forms!frm_NewOrderEntry2.cboStore = Forms!frm_NewCustomerEntry!StoreInfo_ID
DoCmd.Close acForm, "frm_NewCustomerEntry", acSaveYes

End Sub

It does what I expected Pass the 2 pieces of data along to the new form. Closes and opens the new form.

What I did not expect is that it can execute even if controls with required values of yes are not entered.

What is it I am doing wrong?

Jason
 
Private Sub cmdNewOrder_Click()

DoCmd.OpenForm "frm_NewOrderEntry2", acNormal, , , acFormAdd
Forms!frm_NewOrderEntry2.cboCustomer = Me.ID
Forms!frm_NewOrderEntry2.cboStore = Forms!frm_NewCustomerEntry!StoreInfo_ID
DoCmd.Close acForm, "frm_NewCustomerEntry", acSaveYes

End Sub

What I did not expect is that it can execute even if controls with required values of yes are not entered.
Looks like you're the one saving the record in code :)
 
So the acSaveYes bypasses the required fields? So how should I have handled the event?
 
Depends. Where do you not want it to save, frm_NewCustomerEntry form or frm_NewOrderEntry2 form?
 
I have 5 or 6 controls with the Validation Rule Is Not Null.

Normally if the user navigated to a new record the db prompts the Validation Text associated with the Null Control.

I have the form in Data Entry Mode and have disabled the navigation bars, close button and record selectors.

What I want to do is validate the form as normal, Save the record, Navigate to the new Form frm_NewOrderEntry2 and pass the 2 pieces of data the store the customer is buying from and customer_ID to populate the order record.

The code I used passes the data and handles the opening and closing of the form just fine but I still need to validate the controls....

Thanks Again!
 
The correct order of checks should be:

1. Check if the Customer details have been filled in.
2. If it hasn't then it shouldn't open the NewOrderEntry form.
 
So in the control I have to code the checks for the controls in IF statements?

As an example:

IF IsNull Forms!frm_CustomerEntry!FirstName Then
MsgBox("Please Enter A First Name")

ElseIF IsNull Forms!frm_CustomerEntry!:LastName Then
MsgBox("Please Enter A Last Name"

ElseIf......

Else

My other code
End IF
 
Here I thought I understood this command...

Code:
    DoCmd.Close acForm, "frm_NewCustomerEntry", acSaveYes
What is it I am doing wrong?

Jason

acSaveYes is the option to saving design changes to the form, not for saving changes to the current record.

This command saves changes to the current record...

Code:
    If Me.Dirty Then
        DoCmd.RunCommand acCmdSaveRecord
    Else
        MsgBox "There were no modifications made to the current record.", vbInformation, "Invalid Save"
    End If
 
If you want to ensure that the values of all or certain controls in the Customer form are not "empty" before opening the form then you Nest the IF statements using IF...ELSEIF...

If you want to ensure that AT LEAST one of the controls has a value, then you don't nest, you have to have an IF... END IF for each check.

You handle all of this in the ON CLICK event of the button that opens the form.
 

Users who are viewing this thread

Back
Top Bottom