warn a user to enter data in parent form

pablavo

Registered User.
Local time
Today, 14:42
Joined
Jun 28, 2007
Messages
189
Hi all

I’m trying to write a little code and keep coming up against barriers.

I have a main form with a sub form named sfrmYear. Also, on the main form I have another sub form named sfrmApproved.

SfrmApproved is actually linked to sfrmyear via a txtLink (=sfrmYear.Form!YearID) the txtLink being the master field.

Here’s my problem. For some reason Access is accepting the user typing into sfrmApproved when a Parent record has not been created for sfrmYear. In the tables the tblApproved will have the amount but not the YearID which will be blank.

I would like to create some code that will stop the user from doing this and warn them that they have to create a record within sfrmYear before creating a record within sfrmApproved.

I can’t imagine it would need a lot of code, however, I’m unsure what it would be and I’m finding difficulties refrencing to sfrmYear when I use sfrmApproved event to create the code.

Thank you in advance for any help anyone can provide.
 
I have a tendency to make the form force the user to do the right thing. In this case I would probably disable the SubForms until the MainForm was filled in properly.
 
First of all ruralguy is right.
But if you have to do it your way, then run a dcount to sfrmyear forms table to see if the same link field value exist with SfrmApproved's link field value . If dcount is zero then warn the user...

Olcaym
 
Thanks folks for getting back to me on this one.

I'll have a look at the Dcount and see how that would work.

I take it RuralGuy, when you say Disable, you're refering to the Enable in properties. I tried that and used:
Forms!frmYear!sfrmApproved.Enabled = True within sfrmYear but was reluctant to use this feature. I wasn't really sure what event so I put it in the AfterUpdate event.

The problem for me was that when a user wanted to update sfrmApproved they would have to update (an existing record within) sfrmYear before doing this. It could be that event though.

I tried this within sfrmApproved:

If Me.YearID.Value & "" = "" Then
MsgBox "Please Enter a New Project Year before adding a record.", vbInformation
DoCmd.RunCommand acCmdUndo ' Delete the record
Forms!frmProject!sfrmYear.SetFocus ' On to Parent form
End If

*frmProject being the Main form.

Thanks for the help:)
 
Thanks folks for getting back to me on this one.

I'll have a look at the Dcount and see how that would work.

I take it RuralGuy, when you say Disable, you're refering to the Enable in properties. I tried that and used:
Forms!frmYear!sfrmApproved.Enabled = True within sfrmYear but was reluctant to use this feature. I wasn't really sure what event so I put it in the AfterUpdate event.

The problem for me was that when a user wanted to update sfrmApproved they would have to update (an existing record within) sfrmYear before doing this. It could be that event though.

I tried this within sfrmApproved:

If Me.YearID.Value & "" = "" Then
MsgBox "Please Enter a New Project Year before adding a record.", vbInformation
DoCmd.RunCommand acCmdUndo ' Delete the record
Forms!frmProject!sfrmYear.SetFocus ' On to Parent form
End If

*frmProject being the Main form.

Thanks for the help:)
 
You would decide in the Current event of the MainForm if the SubForms need to be disabled. Then you can set the focus to the YearID control and check in the AfterUpdate event of the control and if completed properly then enable the SubForms.
 

Users who are viewing this thread

Back
Top Bottom