MS Access VBA

Posted on 2012-12-27
Last Modified: 2012-12-28
I have inherited a mess.
A MS Access app (ADP) with many many nested forms.

In this wuestion I have

Parent Form
      SubSubForm on SubForm

On the parent form I have a combobox (cmbVisits)

On the ParentForm cmbVisits_Change() event I want to
execute a public sub on SubForm
execute a public sub on SubSubForm

I'm able to execute the sub form public sub with this...

I've tried all kinds of permutations of the sub sub form
Like this one...all with a object error message
Question by:lrbrister
  • 9
  • 5
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38724457


the syntax would normally be:


Author Comment

ID: 38724472

I received this error


Author Comment

ID: 38724482
This is the actual forms and path left to right...still getting same error messgage

LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38724487
You will have to provide more details.

Is the SubSubforms actually nested inside the SubForm, or are there just two subforms on the main form?

What are the Control Names of each of the subform controls (don't confuse this with the value in the SourceObject property of each item.
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38724502
You might have to declare that function (in the code section of the SubSubForm) from Private to Public.

As mentioned above, make sure you are using the "control names" and not the "source Object" to refer to these subforms.

Author Comment

ID: 38724513
On the main (ClientVisits) form is the combobox
This same ClientVists form has 3 sub forms...and the first one has it's own sub form

1. MarketingVisitationClient
     a. MarketingVisitationClientContactsWorklist
2. ClientVisitContactEvent
3. ClientVisitsNearbyLV

I can execute the public sub on #2 with

I am trying to execute the public sub on 1.a. named loadContactData

Author Comment

ID: 38724522
It IS a public sub in the sub sub form.

Public Sub loadContactData()
        Dim cmd1 As New ADODB.Command
        Dim rst1 As ADODB.Recordset
        cmd1.ActiveConnection = CurrentProject.Connection
        cmd1.CommandType = adCmdStoredProc
        cmd1.CommandText = "usp_MarketingVisitContactsGet"
        cmd1.Parameters("@VisitID") = Nz(Me.Parent.cmbVisits, 0)
        cmd1.Parameters("@ClientID") = Me.Parent.txtClientID 'Me.Parent.Parent.getClientID()
        Set rst1 = cmd1.Execute()
End Sub

Open in new window

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.


Author Comment

ID: 38724554
fyed, make sure I was able to see the first subform from the parent (ClientVisits) I ran a messagebox in the following call and it worked


I'm just not reaching 1.a from my list above
LVL 47

Accepted Solution

Dale Fye (Access MVP) earned 500 total points
ID: 38724563
That error makes more sense now.

Your line 9 refers to "me.Parent.cmbVisits"  but that combo is not in the parent form, it is in the parents parent, so try:

cmd1.Parameters("@VisitID") = NZ(me.parent.parent.cmbVisits, 0)

Put a breakpoint in the LoadContactData subroutine and confirm that those parameters are being  set correctly.

Author Comment

ID: 38724610

I know I'm missing something obvious (Like I just missed the Parent path)
I'm frustrated with myself.

But it's still not getting to that breakpoint...tried that myself previousely

Getting this error screen now

LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38724661
1.  Are you certain it is running the other code (loadQuestions).  Have you put a breakpoint in that code and stepped through it?

2.  Are you certain that subform is actually loaded at the point where this occurs?  Instead of trying to run code on that subform, try popping up a message box with the value in one of the controls on that subform.

msgbox me.MarketingVisitationClient.form.MarketingVisitationClientContactsWorklist.form.txtSomeControl

I must admit that I have never felt the need to call a subroutine nested in the code module of a sub-sub form.  Is there a reason that this code could not go into a general code module, rather than a forms code module?

Is there a reason you could not call that procedure from within the LoadQuestions subroutine of the MarketingVisitationClient form?

Instead of

Author Comment

ID: 38724885
Well...this entire forms set is part of a much larger Client Visits and Schedu;ing process.

I must admit, it's been years since I was in MS Access.  been in AJAX .Net Web Forms and WinForms until this recent job.

The forms are all datasheet views so it's functioning like a hierachy based set of GridViews

Without going into the gory details...
I can't just use a view etc to call in the data.

These forms are all filtered by the Combobox.

How would I do that on my sub_sub form based on the conbobox click...using a general code module?

Author Comment

ID: 38724922
If I go to the sub sub form and put in the stored procedure I can then open the form and (since there are two paramaters to the stored procedure  @ClientID and @VisitID) ...
I can manually enter a ClientID and a VisitID and get the data.

Is there any way to tie that stored proc to the Parent.Parent.Combobox?


Author Closing Comment

ID: 38726985
  Everything you've pointed out to me is correct.  

I know for a fact it works because I've done it in a second database with a similar setup.

There's just something in this particular database that isn't working.

Since your reply 38724563 was what worked in a second database I'll accept that.

Looks like I'll have to find a work around.

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Refreshing a form in Access when saving data? 3 41
Authentication of Web Services 3 46
MS Access Calculation wont work 5 35
Query design issue 2 15
Many companies are making the switch from Microsoft to Google Apps ( Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now