Invalid Outside Procedure

S

Sue

Hi, all.

I am trying to make a command button on my form get the next record OnClick
so the user can enter more data in the cleared text boxes and combo boxes. I
copied and pasted this code right out of the VB code for another database
that works fine for that database, but doesn't in mine:

DoCmd.GoToRecord , , acNewRec

Your prompt responses are very much appreciated!
 
D

Dirk Goldgar

In
Sue said:
Hi, all.

I am trying to make a command button on my form get the next record
OnClick so the user can enter more data in the cleared text boxes and
combo boxes. I copied and pasted this code right out of the VB code
for another database that works fine for that database, but doesn't
in mine:

DoCmd.GoToRecord , , acNewRec

Your prompt responses are very much appreciated!

Where did you paste it? You need to have an event procedure for the
button's Click event, and put that line inside it. If you select the
button in design view, bring up its property sheet, go to the Event tab,
click on the On Click line, and then click the build button ("...") that
will appear at the end of the line, you should be able to get Access to
create the initial shell of the event procedure for you. Then you can
paste that line into it. It would look something like this:

'----- start of example code -----
Private Sub YourButtonName_Click()

DoCmd.GoToRecord , , acNewRec

End Sub
'----- end of example code -----
 
S

Sue

Hi, Dirk.

Thanks for your help. Here's what my code looks like for the OnClick event
procedure:

Private Sub Clear_form_Click()

On Error GoTo Err_Clear_form_Click

DoCmd.GoToRecord , , acNewRec

Exit_Clear_form_Click:
Exit Sub

Err_Clear_form_Click:
MsgBox Err.Description
Resume Exit_Clear_form_Click

End Sub

So it appears to me to be inside the event procedure. Any other ideas?
 
D

Dirk Goldgar

In
Sue said:
Hi, Dirk.

Thanks for your help. Here's what my code looks like for the OnClick
event procedure:

Private Sub Clear_form_Click()

On Error GoTo Err_Clear_form_Click

DoCmd.GoToRecord , , acNewRec

Exit_Clear_form_Click:
Exit Sub

Err_Clear_form_Click:
MsgBox Err.Description
Resume Exit_Clear_form_Click

End Sub

So it appears to me to be inside the event procedure. Any other
ideas?

I doubt that code is the source of your problem. Set the module to Full
Module View (one of the two little buttons at the lower left corner of
the module window), and scan from top to bottom for an executable
statement that is not enclosed in a procedure.
 
D

Douglas J. Steele

Doing a Compile (on the Debug menu) should identify the offending
statement(s), shouldn't it Dirk?
 
D

Dirk Goldgar

In
Douglas J. Steele said:
Doing a Compile (on the Debug menu) should identify the offending
statement(s), shouldn't it Dirk?

You're right, Doug. For some reason, I assumed that Sue must have done
a compile, and that it still hadn't highlighted the offending line.
Just compiling would have found it quicker than a manual scan. Sorry
about that, Sue.
 
D

Dave

Sue said:
You gave me good advice. I went through all my code and realized I had a
line that should have been commented out. It took me a while to figure out
what you were talking about when you mentioned "setting the module to Full
Module View (one of the two little buttons at the lower left corner of the
module window)." Feels so good to make a step in the right direction
(however small that may be) after days of troubleshooting and getting
nowhere!! You da man!
 
D

Dave

I have the same problem as Sue. I did the compile (without errors) and
searched my doc as suggested. I found a DIM which should have been PUBLIC
(for a global definition) which I changed. It still doesn't allow me to do
any ONxxxx event transfers to a procedure. I can do a ONxxxx to a macro
however.
 
Top