Form won't execute unless all criteria is satisfied (1 Viewer)

The Bey

Registered User.
Local time
Today, 19:45
Joined
Jun 21, 2011
Messages
84
I have a form which somebody will use to populate a table/report, but I want to make sure that all required boxes have data entered before the table/report is populated with the form's info.

I was thinking I could use the isNull but I'm not sure where I should put it or how.

I have a button that opens a seperate form which displays all of the previously entered data, so would I need to place something within the button's event?

Also I would like the previous form to close once the second form has been populated. I've done this earlier but when it comes to a form that I need to get info from, the transfer never works properly; this has been done as a macro that is set it to "RunCommand - CloseWindow" then "OpenForm - FormName". When I turn it the other way around, it merely closes my newly opened window. This sounds stupid but how can I do this?
 
You can use IsNull.
In the form's before update event, code something like this:
If IsNull(Me.[Textbox1] Or IsNull(Me.[Textbox2]) Or IsNull(Me.Textbox3]) Then
Cancel = True
MsgBox "You must enter a value for every box."
End If.

To make this code run from a button, code the button like this:
Private Sub ButtonName_Click()
If Me.Dirty = True Then
Me.Dirty = False
End If
DoCmd.OpenForm "NameOfForm"
DoCmd.Close acForm, Me.Name
End Sub

Note: replace my object names with yours.
 
What will be updated in the BeforeUpdate event?

Will that have to be done with update code, so that when I, say, click the button you've described, it'll populate a table? Because at the moment i'm setting it to move individual details into a more concise form... so should I set the code in the BeforeUpdate event in the latter of the form's events?

And with "DoCmd.Close acForm, Me.Name", would the "Name" be the name of the form I wish to close?

Cheers
 
This sounds like a lot of work - to create 2 forms with buttons and code when you could do the data entry all in one go in one form.

I suggest that you make this first form a bound form and save the data in the table.
When you open the second form, it will be bound to the same table, so the previous form's data entry will appear on the form anyway.

About the before update event.
Create a before update event on the form and put in the code I suggested in my last post.

Me.Name - is our quick and easy way to refer to the form where the code is executing - it makes coding easier and quicker.
 
I know that it's a long winded and needlessly complicated way of doing it, but thus far it's working nicely and I understand it so I've stuck at it.

The problem with me binding my form to the table is that the control sources of my textboxes are connected to a combo box on my form; That combo is referencing the table I'm interested in.

I then have a set of combo boxes bound to 11 different tables (to call values from) then I have these values in sums in textboxes whos control sources are IIf statements. Basically I need to select a load of options to get an answer output, and then add that to the already existing table that the subject was selected from and overwrite any previously existing data with updated data.

This is all working, even the updating section, but I still can't get the "Dirty" statements to work. i.e. when I add a null value, it comes up with the textbox saying I've added a null value, but still carries on with the update and just ignores what I've said.

So do I need to add anything to do with the my objects in the .Dirty statement?
 

Users who are viewing this thread

Back
Top Bottom