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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i get faq181-291with sub forms?

Status
Not open for further replies.

dotolee

Technical User
Jan 27, 2008
134
CA
I've tried faq181-291 's code and it works great for independant forms. But how do you make it work for subforms? I have a main form called InclusionExam. This has a subform embedded in it called frmIESection1. The code below is the code I have for frmIESection1's before_update method. The line that's been commented out only works if the form is loaded as an independant form.
I'm getting an error saying that the form I'm referencing doesn't exist!
Please help.

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Call basLogTrans(Me, "PID", PID) ' standalone mode.
Call basLogTrans(Forms!InclusionExam!frmIESection1.Form, "PID", PID)

End Sub
 
For me, the basAddHist function should accept a Form object instead of a string as parameter.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
So... how do i pass the form itself? I guess I need to find out what the equivalent of ME is for a sub form.
 
In basLogTrans, replace this:
Call basAddHist(Hist, Frm.Name, MyKey.Name, MyCtrl)
with this:
Call basAddHist(Hist, Frm, MyKey.Name, MyCtrl)

In basAddHist, replace this:
Public Function basAddHist(Hist As String, Frm As String, MyKeyName As String, MyCtrl As Control)
...
!MyKey = Forms(Frm).Controls(MyKeyName)
...
!frmName = Frm
with this:
Public Function basAddHist(Hist As String, Frm As Form, MyKeyName As String, MyCtrl As Control)
...
!MyKey = Frm.Controls(MyKeyName)
...
!frmName = Frm.Name

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
will this still work for independant forms too?
 
I've tried PHV's suggestion above and I receive error 2450, "...Access cannot find the subform referenced...."

Anyone know how to correct this?

Thanks,
 
scorpio, what is your actual code and which line raises the error ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have an AuditTrail function that is based on the microsoft FAQ (don't have a link handy, sorry) and just implemented it for a sub-form.

Set MyForm = Screen.ActiveForm
If MyForm.Name = "MainMenu" Then Set MyForm = Screen.ActiveControl.Parent

Since I know that "MainMenu" has no bound controls, and two subforms that I want to audit. The active control will be on one of the subforms, so capturing its parent gives me the subform when screen.activeform only gives the main form.

(Notes on subform vs mainform syntax)
 
Much the same is trtue for a (any) control. If you have the specific control, referencing it's parent will return a higher level object ... until there are no such objects. Wheather attempting to reference the next item by traversing the ladder up down or even laterally only requires the 'knowledge' of the object(s) above / below / beside the current object. You can easily obtain these lists (e.g. the 'knowledge') programmatically, usually with simple enumeratiopn loops. Reference to a subform (when the FORM is known is obtained by this structure. Setting focus to the (subform) object should permit the use of the faq with minimal modification. Recursively searching a (form) object for all possible sub forms and traversing each for the information may prove somewhat more of a challenge.

MichaelRed


 
Michael, what do you think about my suggestions (27 Jan 08) ?
 
PHV said:
" ... think about my suggestions ... "

I haven't had / taken the opportunity to actually implement or test them. At a glance they seem to be a workable approach, but a-la my last (and general approach) I would prefer to first of all (and particularly here in Tek-Tips) to provide the concept and minimalists versions of actual code (firmly rooted in the give a fish ... teach to fish ... approach to education). The FAQ is somewhat more detailed than this, but should (may not?) adhere to the generic theme of teaching vs feeding. Further, I am not at all in favor of the implied functionality (including only a PART of the changes in an AUDIT trail. The function is intended to collect ALL changes to the DATA, not just selected items (fields). After all, anything less is not really an audit?

Hence I would opt for the recursive search for any sub-forms , and include any / all changes from the "Top-Down" perspective.

I, along with many others, have often (and should universally) include the standard set of disclaimers (error checks in particular; lack of exhaustive testing; ... ). The functions are usually / often written in response to specific threads / posts but are likely to be adopted -with out adaptation- to other uses. This always puts the user at the mercy of the vagaries of the divers situations.

I originally intended and used the 'audit trail' of changes as a part of an application where there was a 'need' to be able to step through the sequence of changes of data elements from an individual field of an individual table to the complete roll-back of the data base to the state before a specific individual change was made. At that time, I could not conceive of doing a complete back up of the entire data base after every record was committed. I still cannot.

The next closest approach I know of (copy every {entire} record to an ancillary / audit table) seemed to require a great deal more effort and storage than saving individual fields.

I suppose [bold]dotolee[/bold] and / or [bold]scorpio1769[/bold] will have special considerations which make the subform du-jour the important fact / issue and the main form irrelevant to their needs, but I still prefer to leave the completion of the proof to the student ...

On the other hand, I am awed and amazed at your mastery of these subject matters.

Respectfully,



MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top