Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

howto...subform vs form events

Status
Not open for further replies.

RaineSpencer

Programmer
May 8, 2002
25
US
Hi --
I have a form with a subform (with linkmaster and linkchild set up). I want some code to run when data in a particular control on the subform is changed. I have tried placing the code in the subform's before update event, but it never runs when the form is being used as a subform (it does run, and works fine, when the form is a standalone form). I have tried placing code in the main form's ondirty event, but changes to data on a subform does not trigger the ondirty event on the main form. When or how can I either trigger the subform's update events, or get the main form to notice when data on a subform is entered or updated?

many thanks in advance,

Lorraine
 
Lorraine:

What do you want the code to do?

Update a record?
Delete a record?
Move to a particular Record?
Call your dog in for supper?

It would help us to give you code examples if we knew what you needed it to do.

Thanks.


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 

I want it to update some values in another table, and add a record to yet another table based upon values on the form and the subform...something like this, though form and subform would be changed to the names of the forms, once I know where the code should go (on the form or the subform....).

if subform.[date cancelled] has been changed this should execute:
Set db = CurrentDb
Set rs = db.OpenRecordset("tblNotes", dbOpenDynaset, dbSeeChanges)
rs.AddNew
rs![note date] = subform.[Date Cancelled]
rs![Person Responsible] = form.[current user]
rs![Reg Id] = subform.[Reg Id]
rs![Meeting Code] = form.[Meeting Code]
rs![Person ID] = subform.[Person ID]
rs![Notes] = "No Show" & " for meeting " & form.[Meeting Code]
rs.Update
rs.Close


strsql = "UPDATE tblRegistration SET tblRegistration.[Date Cancelled] = Now(), tblRegistration.[Cancellation Fee] = [tblregistration].[reg fee] Where tblregistration.[reg id]= " & subform.[Reg Id]
Debug.Print strsql
Set qdf = db.CreateQueryDef("", strsql)
qdf.Execute
strsql = "UPDATE tblRegistration SET tblRegistration.[Reg Fee] = 0 Where tblregistration.[reg id]= " & subform.[Reg Id]
Debug.Print strsql
Set qdf = db.CreateQueryDef("", strsql)
qdf.Execute
db.Close
 
Add it to the After Update event of the field.


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
Suave, yes, and much appreciated, but it still doesn't work...The subform, as a form on its own, executes the after update event for the field, just the way I want it to (and the code works). The subform used as a subform does not. I put a debug.print before any real code in the after update event to make sure that it isn't a logic error or syntax that is mucking me up. The debug.print prints when the form is used on its own and I change the data in the control. When I use the form as a subform,make the same change to the data in the control, the debug.print never prints so I know the event is never triggered.
 
Thanks Gambit. I found the problem. Events weren't being triggered on the subform because I was working on a dummy subform. The 'real' subform was hidden behind the subform I was working on (the original programmers used this to save themselves a few steps, but it caused me a lot of trouble)...

Lorraine
 
Ah...those nasty hidden subforms...almost as bad as those visible macros...(I hate macros)....

:)


"I know what you're t'inkin', ma petite. Dat Gambit... still de suave one, no?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top