Link to home
Start Free TrialLog in
Avatar of Fred Fisher
Fred FisherFlag for United States of America

asked on

Catch Error 3314

I am going through my program inserting error trapping where necessary.  I have one that is a hard one to crack.  I have a form frmTitles with subforms subfrmSongs in the footer of subfrmSongs are two other tables frmMMSongComposer and frmMMSongGroup.

The error occurs if the record selector in subformSongs is left on a "new" record and you click on either frmMMSongComposer or frmMMSongGroup.  The error is 3314 saying that an error must be entered.  I would like to put in an error routine that would catch this and put the record selector to the first current record in subfrmSongs .  Any ideas I am thinking the Got Focus event in frmMMSongComposer and frmMMSongGroup is where the code should go.

At this point when the error occurs there is no way out except end task in task manager and start over as the error just keeps looping on itself over and over.
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

I prefer to do this by making the subform controls visible but disabled  (or hidden) until the current record on the main form is saved.  Then enable (or unhide) those two subforms.

Access attempts to save the record on the main form when you set the focus to a subform.  If there is no data or insufficient data in the main form to allow it to save the record, then an error will be raised.  You might want to add some code in the main forms BeforeUpdate event, something like:
Private sub Form_BeforeUpdate(Cancel as integer)

    if Trim(me.SomeControl & "") = "" then 
         msgbox "Fill in field1"
        Cancel = true
    elseif Trim(me.SomeOtherControl & "") = "" then
         msgbox "Fill in second field"
         Cancel = true
    end if

End Sub

Open in new window

This would prevent the main form from saving and should prevent the error message you are currently getting when trying to move the focus into one of the subforms.
Avatar of Fred Fisher

ASKER

The problem is that this error occurs when no information should be entered.  To recap when entering Songs after you enter the last song the record selector goes automatically to where you would enter another song (continuous form) but you are finished entering songs and now you are going to enter composers for each song.  Unless you move the record selector out of the "New" spot the error message occurs when you click to enter a composer.  At that point you are stuck in a loop and have to use task manager to "end task" access and start over.
Well, that would actually make sense.  You need to select a song in order to assign a composer or a group in the subform.  If you manually move the focus on the continuous form to a record that contains a song, do the subforms work properly?

One option might be to use the subform controls Enter event to move the cursor to the first song in the album that does not already have a composer assigned.  Don't know whether this would work or not as I don't recall ever trying something like this.

Another would be to use the main forms Current event to enable/disable the subforms, something like:
Private sub Form_Current

    Dim bEnableSubs as boolean

    bEnableSubs = NOT me.newrecord
    me.subComposers.Enabled = bEnableSubs
    me.subGroups.Enabled = bEnableSubs

end sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fred Fisher
Fred Fisher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial