VBA execution

L

Len B

I have a couple of general questions about VBA.

Is there a way to single step through the start-up code of an application?
Effectively, what I am looking for is a setting somewhere that will set a
breakpoint at the very first line of code, allowing me to single step from
there when I first launch the application.

Secondly, is there a resource which will tell me in what order SUBs will be
executed? Obviously, for a form, OnActivate will execute before OnCurrent
but the order for others is not so apparent.

I have often wondered about execution order but what brought this to a head
was that I was editing a form (the start-up form Assets) containing a
DateSold text control and a Status combo control (to select from InService,
Inactive and Sold). I added AfterUpdate code to each.
For the DateSold it set the combo to sold.
For the combo I sent the cursor to the DateSold field if it was blank.

Now when the application launches, I am confronted with a series errors,
none of which refer to selling an asset. A dialog box demands a value for
Forms!Assets!AssetID. Humouring it with a valid value results in Runtime err
40036. Choosing Debug opens the code window in the IsLoaded function... etc.
etc.

I want to be able to see, step by step, what is happening. I cannot believe
my AfterUpdate code is at fault because I commented it out but still the
errors come.

TIA
 
T

Tony Toews [MVP]

Len B said:
Is there a way to single step through the start-up code of an application?
Effectively, what I am looking for is a setting somewhere that will set a
breakpoint at the very first line of code, allowing me to single step from
there when I first launch the application.

You need to determine just how your code starts up. That is is there
an autoexec macro calling a function or a startup form?

Then you can either use a breakpoint or a Stop command in that code.
I prefer a Stop command as breakpoints are occasionally troublesome.
Secondly, is there a resource which will tell me in what order SUBs will be
executed? Obviously, for a form, OnActivate will execute before OnCurrent
but the order for others is not so apparent.

Yup, the Access help has a page on order of events .

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
L

Len B

Thanks for that Tony.
There is no autoexec macro but, as I said, there is a startup form. The
question now is where in this form do I put the Stop command. Obviously I
cannot set a breakpoint in an application that isn't running yet.

I found the help page you mention and I figured it this way. The form open
sequence of events will run before any control events will so, the Stop
command should be the first line of the first event in the list Open ->
Load -> Resize -> Activate -> Current. Turns out that this is Activate. I
did that and I am still asked for an AssetID at launch.

Am I wrong? Is there something such as a default control that gets hold of
the steering wheel before Form_Open (or Form_Activate in this case) does?
 
J

John W. Vinson

I
did that and I am still asked for an AssetID at launch.

Sounds like the startup form is based on a Query which has AssetID as an
unresolved parameter.

Does holding down the Shift key as you open the database help? It should
bypass the Startup action, unless the developer disabled that capability.

John W. Vinson [MVP]
 
L

Len B

John W. Vinson said:
Sounds like the startup form is based on a Query which has AssetID as an
unresolved parameter.

No. Startup form is based on the table Assets. However, it has a tab control
with 3 tabs. Two of the tabs have subforms. Both subforms are based on
tables - Maintenance and Depreciation. Each of these tables is joined to the
Assets table's primary key.
Does holding down the Shift key as you open the database help? It should
bypass the Startup action, unless the developer disabled that capability.

John W. Vinson [MVP]

Holding shift down at launch takes me to database window without any errors.
The startup form doesn't open. In normal operation the database window is
hidden. I guess that tells us that the problem is somehow with the form. I
proved this by opening the form and I'm asked again (twice) for an AssetID.
Sounds like the subforms might be the issue. Would any events in them
execute before the parent's Form_Activate event?
 
T

Tony Toews [MVP]

Len B said:
There is no autoexec macro but, as I said, there is a startup form. The
question now is where in this form do I put the Stop command. Obviously I
cannot set a breakpoint in an application that isn't running yet.

I found the help page you mention and I figured it this way. The form open
sequence of events will run before any control events will so, the Stop
command should be the first line of the first event in the list Open ->
Load -> Resize -> Activate -> Current. Turns out that this is Activate. I
did that and I am still asked for an AssetID at launch.

Then John is correct. The query on which the form is based may be
missing the AssetID field and the subforms parent property uses that
field. Or something similar.
Am I wrong? Is there something such as a default control that gets hold of
the steering wheel before Form_Open (or Form_Activate in this case) does?

Yes, Access will setup the various queries, subforms, etc, before
Access starts to execute any code.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
J

John W. Vinson

No. Startup form is based on the table Assets. However, it has a tab control
with 3 tabs. Two of the tabs have subforms. Both subforms are based on
tables - Maintenance and Depreciation. Each of these tables is joined to the
Assets table's primary key.


Holding shift down at launch takes me to database window without any errors.
The startup form doesn't open. In normal operation the database window is
hidden. I guess that tells us that the problem is somehow with the form. I
proved this by opening the form and I'm asked again (twice) for an AssetID.
Sounds like the subforms might be the issue. Would any events in them
execute before the parent's Form_Activate event?

Yes; the Subforms open before the mainform does, and the subform's events
follow the same sequence as the mainform. The fact that you're getting
prompted suggests that each subform is referencing AssetID in its query, but
that there is no field of that name in the table upon which the query is
based. Try opening each subform as a standalone form and check its
Recordsource.

John W. Vinson [MVP]
 
D

Dennis

ANY TIME you are asked for a "parameter value", you can rest assured that
it's a QUERY doing the asking. VBA code in a form will just throw an error.
 
L

Len B

Sorry for the delay guys. Been sick.
The story so far -
Tables include "Assets" pk=AssetID
"Maintenance" pk=MaintenanceID fk=AssetID
"Depreciation" pk=DepreciationID fk=AssetID
Startup form called "Assets"
based on table "Assets"
has text control "AssetID"
on a tab control
has subform Maintenance based on query q below
has sub subform "Maintenance subform" based on table Maintenance
has subform Depreciation based on query q below
has sub subform "Depreciation subform" based on table Depreciation
both subforms have only Open and Activate events
Open event checks that parent is open. MsgBox if not.
Activate event is DoCmd MenuItem ... acSaveRecord : Me.Requery
neither sub subform has any event handling

q [ SELECT DISTINCTROW Assets.* FROM Assets ]
[ WHERE (((Assets.AssetID)=[forms]![Assets]![AssetID])); ]

All the above worked fine until I added AfterUpdate handling to two
unrelated controls (DateSold and Status) both of which I have
subsequently commented out. Everything between Private Sub & End Sub.

I have added Stop commands to Activate events of parent and both subs,
but execution doesn't reach any of these Activate events.

Here's what happens.
I open app, bypassing auto launching.
Open form Assets
Asked for Forms!Assets!AssetID
Responded 7 <Enter>
Runtime 40036 <<End>> <<Debug>> <<Help>>
<Debug> => IsLoaded of Module GlobalCode, If CurrentView<>DesignView Then
Move cursor to matching End If <Ctrl + F9> <F5> i.e. SetNext and Run
MsgBox saying Maintenance form only openable from Assets form.
(generated by Open event of subform Maintenance above)
<Ok> (to dismiss MsgBox)

Asked for Forms!Assets!AssetID a second time
Responded 7 <Enter>
Runtime 40036 <<End>> <<Debug>> <<Help>>
<Debug> => IsLoaded of Module GlobalCode, If CurrentView<>DesignView Then
(hovering on CurrentView = tooltip "Method 'Item' of object 'Forms' failed"
Cursor to next statement <Ctrl + F9> <F5> i.e. set IsLoaded to True this
time

Info PopUp OkOnly Error which says
"The expression OnActivate you entered as the event property setting
produced the following error : Procedure declarations does not match
description of event or procedure having the same name.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event or macro.
<<Show Help>> <<Ok>> "
<ShowHelp> lists following possibilities
-Missing Reference - see kb283806 (No missing references found)
-An expression is misspelled (Not that I can see)
-A udf is declared as Sub or as Private Function in a module.
-Security in Access set to Med or High and Jet 4.0 SP8 not installed
As for udf, nothing has changed and it worked before
Security level unchanged but all updates always done anyway.
<Ok> (to dismiss error popup)

Info PopUp OkOnly Error which says
"The expression OnCurrent you entered as the event property setting
etc etc as previously except Current not Activate
<ShowHelp> Same possibilities
<Ok> (to dismiss error popup)

Form "Asset" displays (AssetID=1) but tab control doesn't display subforms.
<NextRecord> prompts for Forms!Assets!AssetID twice (answer 2)
Depreciation subform and sub subform appear.

Subsequent <NextRecord> clicks goes through the prompt for ID and
popup cycle. If I enter the ID in the prompt to match the target
record, the subforms display. If I get one right and one wrong only one
subform will display.

Any ideas anyone?
 
G

George Nicholson

ANY TIME you are asked for a "parameter value", you can rest assured that
it's a QUERY doing the asking. VBA code in a form will just throw an
error.

Simply not true.

One example: A nonexistant field name in a report's grouping/sorting dialog
will also generate a "parameter" prompt.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top