Update Subform Control From Another Subform (1 Viewer)

jwleonard

Registered User.
Local time
Today, 08:35
Joined
Apr 13, 2005
Messages
83
I have a main form with two seperate subforms. On subform1 I have a control with an after update event to update one field on the first record on subform2.

The issue I am having is that subform2 is a continuous form that doesn't allow additions and sometimes there are no records present. So when there aren't any records I get an error since I can't update a record that doesn't exist.

Does anyone know how to deal with this issue.
 

rat_b76

Registered User.
Local time
Tomorrow, 01:35
Joined
May 20, 2003
Messages
37
Hi,

Searching for 'Error Trapping' should bring up plenty of posts which will deal with the problem that you describe - hopefully anyway.

Cheers

Rat_b76
 

jwleonard

Registered User.
Local time
Today, 08:35
Joined
Apr 13, 2005
Messages
83
Well I tried searching for Error Trapping and read everything I thought looked relevant, but couldn't find anything I could make work. I am self taught and there are a lot of holes in my Access knowledge so I might have looked right at it and didn't know it! I think I might need more of a direct approach on this one! Thanks for the tip and I will keep looking until I get another reply.
 

RuralGuy

AWF VIP
Local time
Today, 09:35
Joined
Jul 2, 2005
Messages
13,825
You can test the RecordCount of subform2 for > 0 before attempting to set any fields.
 

rat_b76

Registered User.
Local time
Tomorrow, 01:35
Joined
May 20, 2003
Messages
37
Hi,

What you can use is something like, at the start of your event

Code:
On Error Goto 10
<<All your code goes here as normal>>
Exit Sub
10 MsgBox "There are no records",Vbokonly+vbinformation,"No Records"
Exit Sub

The Exit Sub at the end of your code stops it from progressing to your error code, additionally, you don't have to use the Message Box, you can just exit the sub and the user will not know any difference.

Have a go, and play - hopefully this is what you were after?

Cheers

rat_b76
 

Users who are viewing this thread

Top Bottom