Header to detail tab code issue

G

Guest

I have made a small text box in the header area and put the code Me.[Date
Sold].SetFocus (Date Sold being the name of the text box I would like to tab
to) in the "Got Focus" event. However for some reason it does not work, I
get an "Invalid outside procedure" error every time.

Any advice on how to fix this problem would be most welcome.
 
J

John W. Vinson

I have made a small text box in the header area and put the code Me.[Date
Sold].SetFocus (Date Sold being the name of the text box I would like to tab
to) in the "Got Focus" event. However for some reason it does not work, I
get an "Invalid outside procedure" error every time.

Any advice on how to fix this problem would be most welcome.

If you're typing the expression directly into the event property... it won't
work. And I'm not sure what you're trying to accomplish here - from the sound
of it, you're using the smalltextbox GotFocus event to instantly REMOVE the
focus onto the DateSold textbox; you'ld never be able to do anything in the
small textbox at all! (Maybe that's your intent).

What you need to do is click the ... icon by the GotFocus event and choose
Code Builder; Access will give you a Sub and End Sub line. Put the SetFocus
command between them. If you have code that is *not* between a Sub and an End
Sub (or Function and End Function) line, it's "orphan code" and will generate
this error.

John W. Vinson [MVP]
 
G

Guest

The box is just there to hold code allowing for a person to tab down from the
header to the detail section once they get to the last field in the header.
Sorry re-reading my post I see I did not make that very clear, I am just to
the point of frustration with this thing as I have been working on the
problem for days now.

The full code looks like so;
Private Sub txtTransferToDetail_GotFocus()
Me.[Date Sold].SetFocus
End Sub

For whatever reason for me this does not work, while for others it has. I
actually got this code from this very forum so I am clueless as to where my
error is.

John W. Vinson said:
I have made a small text box in the header area and put the code Me.[Date
Sold].SetFocus (Date Sold being the name of the text box I would like to tab
to) in the "Got Focus" event. However for some reason it does not work, I
get an "Invalid outside procedure" error every time.

Any advice on how to fix this problem would be most welcome.

If you're typing the expression directly into the event property... it won't
work. And I'm not sure what you're trying to accomplish here - from the sound
of it, you're using the smalltextbox GotFocus event to instantly REMOVE the
focus onto the DateSold textbox; you'ld never be able to do anything in the
small textbox at all! (Maybe that's your intent).

What you need to do is click the ... icon by the GotFocus event and choose
Code Builder; Access will give you a Sub and End Sub line. Put the SetFocus
command between them. If you have code that is *not* between a Sub and an End
Sub (or Function and End Function) line, it's "orphan code" and will generate
this error.

John W. Vinson [MVP]
 
J

John W. Vinson

The box is just there to hold code allowing for a person to tab down from the
header to the detail section once they get to the last field in the header.
Sorry re-reading my post I see I did not make that very clear, I am just to
the point of frustration with this thing as I have been working on the
problem for days now.

The full code looks like so;
Private Sub txtTransferToDetail_GotFocus()
Me.[Date Sold].SetFocus
End Sub

This gives the "invalid outside procedure error"???

Try opening the VBA editor and selecting Debug... Compile <database>. My guess
is that you have some code outside a Sub... End Sub line pair. If you do,
you'll get the erroneous line highlighted.

John W. Vinson [MVP]
 
G

Guest

Heh, you were right, and I had no idea that was causing the issue, I have
only had Access for about a week so I have to say thank you so much for
saving me from going insane!

Though the problem is not 100% fixed, I get no more error message, but
instead of tabbing down to "Date Sold" focus stays on the "code box (for a
lack of a better term). My entire VBA editor looks like so;
Option Compare Database


Private Sub txtTransferToDetail_GotFocus()
Me.[Sales Rep].SetFocus
End Sub

The "code box" is enabled, and the "Date Sold" box is enabled, so once again
I am left asking...what am I doing wrong?

John W. Vinson said:
The box is just there to hold code allowing for a person to tab down from the
header to the detail section once they get to the last field in the header.
Sorry re-reading my post I see I did not make that very clear, I am just to
the point of frustration with this thing as I have been working on the
problem for days now.

The full code looks like so;
Private Sub txtTransferToDetail_GotFocus()
Me.[Date Sold].SetFocus
End Sub

This gives the "invalid outside procedure error"???

Try opening the VBA editor and selecting Debug... Compile <database>. My guess
is that you have some code outside a Sub... End Sub line pair. If you do,
you'll get the erroneous line highlighted.

John W. Vinson [MVP]
 
J

John W. Vinson

The "code box" is enabled, and the "Date Sold" box is enabled, so once again
I am left asking...what am I doing wrong?

The GotFocus event the properties window for the textbox should show

[Event Procedure]

Does it?

John W. Vinson [MVP]
 
G

Guest

Yes sir it does.

John W. Vinson said:
The "code box" is enabled, and the "Date Sold" box is enabled, so once again
I am left asking...what am I doing wrong?

The GotFocus event the properties window for the textbox should show

[Event Procedure]

Does it?

John W. Vinson [MVP]
 
G

Guest

I made a blank database and then imported the data from the old database and
it worked like a charm. However it has made a new problem in that when I
then convert it to a 2003 version from my 2007, it no longer works...

DseHarmon said:
Yes sir it does.

John W. Vinson said:
The "code box" is enabled, and the "Date Sold" box is enabled, so once again
I am left asking...what am I doing wrong?

The GotFocus event the properties window for the textbox should show

[Event Procedure]

Does it?

John W. Vinson [MVP]
 
J

John W. Vinson

I made a blank database and then imported the data from the old database and
it worked like a charm. However it has made a new problem in that when I
then convert it to a 2003 version from my 2007, it no longer works...

I'd suggest reposting in a new thread, so someone who has experience with 2007
can reply.

John W. Vinson [MVP]
 

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