Sub-form referencing issue

Peter1662

New member
Local time
Tomorrow, 04:04
Joined
Aug 30, 2011
Messages
5
New to Access and trying to develop forms to use database as opposed to filling in tables directly.
Simple database based on Microsoft's Contact List having added a "Visit" table which has three fields - VisitID (key), _ContactID (foriegn key to link to ContactID, Notes (memo field to record visit details)
I have renamed Contact Details form to frmContactDetails and included several tabs to show grouped infomration e.g. Business Details, Contact Details, Operational Details, Business Plans, Visit Details and Attachments.
My idea is to be able to scroll through the list of contacts (which works fine) and by opening the Visit Details tab scroll down the list of visit dates and for each visit date highlighted the relevant notes for that visit are displayed in the visit notes subform (this is not working)
My issues are with the manner in which I am referencing the subforms on the Visit Details tab, in particular the visit details (i.e. memo field).
I have created two subforms:
sfrmVisitDates: RecordSource - VisitsQuery
Caption -Visit Dates Subform
Default View - Datasheet

sfrmVisitDetails: RecordSource - Visits
Caption - Visit Details Subform
Default View - Single Form
On the frmContactDetails (on the Visit Details tab):
sfrmVisitDates: Name - VisitDates
Source Object - sfrmVisitDates
Link Master Fields - ContactID
Link Child Fields - _ContactID
Event: On Current - Event Procedure as follows:
Code:
Private Sub Form_Current()
' This code created by Form Wizard.
    Dim strParentDocName As String
    On Error Resume Next
    strParentDocName = Me.Parent.Name
    If Err <> 0 Then
        GoTo Form_Current_Exit
    Else
        On Error GoTo Form_Current_Err
        Me.Parent![sfrmVisitDetails].Requery
    End If
Form_Current_Exit:
    Exit Sub
Form_Current_Err:
    MsgBox Err.Description
    Resume Form_Current_Exit
End Sub

sfrmVisitDetails: Name - VisitNotes
Source Object - sfrmVisitDetails
Link Master Fields - [sfrmVisitDetails].Form.[VisitID]
Link Child Fields - VisitID
When opening (running) frmContactDetails I am presented with the following "Contact Management Database can't find the field 'sfrmVisitDetails' referred to in your expression. Clicking on OK them displays another dialog box Enter Paramerter Value - sfrmVisitDetails.For.VisitID [text box] [OK] [Cancel].

I have read through numerous threads but still can't see the error I am obviously making. I have tried swapping the reference sfrmVisitDetails with [Visit Details Subform] with no success.

I hope someone can see where my error, which I'm sure is very obvious to those more experienced.
Thanks Peter:confused:
 
Which form's On Current event is this on? Is it on the subform or the main form? I believe you said it is on the main form. So if the name of the subform control (control on the main form which HOUSES the subform) is named [Visit Details Subform] then you would use

Me.Controls("Visit Details Subform").Form.Requery

You could probably use

Me.[Visit Details Subform].Form.Requery

as well. Now, because the subform isn't the same name as the subform control, you need to include the .Form. part which tells Access you want a method or property of the subform itself and not the subform control. If the subform control and the subform are named exactly the same then the .Form. part is optional, but I still include it just to be consistent.

See if this helps clear a few things up:
http://www.btabdevelopment.com/ts/ewtrhtrts
 
Bob,
Thanks for getting back to me.
The On Current Event is on the subform.
I will take some time to read over the link you provided and try and work this out myself - I should learn more this way.
Will let you know how I get I get soon.
Thanks
Peter
 
If it is the On Current event of the subform then you wouldn't be requerying itself there. Are you wanting to requery the parent form?
 
I am still studying the link you provided which hopefully will become clear in my head.
I have a main form which displays one company's details at a time. The details are displayed on several tabs with the Company name in the header.
I want to record each visit I have with the companies and as such have created a new table which stores the Visit Date and a Memo, both of which I want displayed on tab 5.
As I scroll through the list of companies, the relevant details (i.e. contact persons, business structure etc.) are updated on the various the tabs.
I expect tab 5 to update the list the dates for that specific company in the visit dates subform and to show the associated memo (second subform) for the first visit date in the list. As I click on the different visit dates I want the second subform (visit details) showing the memo field to refresh (i.e. requery). Therefore I have the On Current event on the Visit Dates subform to requery the Visit Details subform when a new visit date is selected.
Do I not have this correct?
I am changing the names of some of the elements (eliminating any common names) so I can better understand exactly what's going on.
Thanks for your help!
 
Bob,
Thanks for all your help. Between your comments and the link you provided me I now have the subforms working.
I still have a couple of other little associated issues to resolve, but will scan the forum before asking for help.
Not sure how these threads are closed, but this thread has resolved my issue.
Thanks again
Peter:)
 

Users who are viewing this thread

Back
Top Bottom