Error Handling a Form data input (1 Viewer)

ECEK

Registered User.
Local time
Today, 18:00
Joined
Dec 19, 2012
Messages
717
I have a table that has several field that all have to be populated.

On the data entry form is a button to append the data to the main table.

If someone presses the "Append" button prior to all of the data being populated then all hell breaks loose and the stop macro form appears.

I woiuld like advice on how best to manage this error.

I am happy with the pop ups saying that certain fields need to be populated but when it comes the choice of "Do you want to close the database object anyway?" If I select "No" I want to stop the Macro and return to the form to complete the rest of the data.

hope this makes sense.

I'll try to do some reading myself to see if i can figure it out.

Cheers people
 

Minty

AWF VIP
Local time
Today, 18:00
Joined
Jul 26, 2013
Messages
10,355
Part of the code attached to the append button should check for the complete data being present and if not then elegantly stop and ask the user to complete the missing bits.

Eg (AirCode)
Code:
If IsNull(MandatoryField1) OR isNull(MandatoryField2) Then
   MsgBox "Fields are missing data, please complete!)
   Exit Sub 
End If

Do Your Append here
 

ECEK

Registered User.
Local time
Today, 18:00
Joined
Dec 19, 2012
Messages
717
I have entered your code and whilst the initial problem has gone, The form just closes and doesn't append the data.

I have attached the code with your addition, maybe you could see where I'm going wrong?

Code:
Private Sub Command42_Click()
If IsNull(MandatoryField1) Or IsNull(MandatoryField2) Then
   MsgBox "Fields are missing data, please complete!)"
   Exit Sub
End If
    DoCmd.OpenQuery "qry_apd_newcase", acViewNormal, acEdit
    DoCmd.Close acForm, "frm_cases_pending_new_hld"

End Sub
 

Minty

AWF VIP
Local time
Today, 18:00
Joined
Jul 26, 2013
Messages
10,355
Why would the form close? Is the form bound to your table? if it is you'll have to do something like this in the Before Update event property of the Form.

Code:
If IsNull(MandatoryField1) Or IsNull(MandatoryField2) Then
   MsgBox "Fields are missing data, please complete!)"
   Cancel = True
   Exit Sub
End If
 

ECEK

Registered User.
Local time
Today, 18:00
Joined
Dec 19, 2012
Messages
717
Hi Minty, hand on a min. What a dumb cluck !! I hadn't replaced the Mandatory Field1 with my fields !!!!!

Just trying it now hang on a bit I'll get back to you,
 

ECEK

Registered User.
Local time
Today, 18:00
Joined
Dec 19, 2012
Messages
717
I'm having problems because the underlying table doesn't seem to be populating from the form therefore when I go to append there's nothing to append !!
 

ECEK

Registered User.
Local time
Today, 18:00
Joined
Dec 19, 2012
Messages
717
I think I need to validate the form then if "Your" code is correct open an additional form that says "Data Confirmed" which also refreshes the form data to the table. THEN have a button to append the query.
 

Minty

AWF VIP
Local time
Today, 18:00
Joined
Jul 26, 2013
Messages
10,355
I'm having problems because the underlying table doesn't seem to be populating from the form therefore when I go to append there's nothing to append !!

I think you are making this unnecessarily complicated.
Is your form Bound to the Table?
If it is then my second post about using the FORMS's Before Update event should work. If the form isn't bound - and you are suggesting to me that it isn't by the fact you are running an append query, then my first suggestion should work.
 

Users who are viewing this thread

Top Bottom