Code I don't Understand

M

Mary/Phil Stewart

I have a form with a command button. Which when clicked goes to the next
record. However, when it gets to a given record I want the cursor to go a
field other than the first one. The field I want to be focused on is,
"Page". Here is the code I am using:

Private Sub NextATM_Click()
On Error GoTo Err_NextATM_Click


DoCmd.GoToRecord , , acNext
Page.SetFocus

Exit_NextATM_Click:
Exit Sub

Err_NextATM_Click:
MsgBox Err.Description
Resume Exit_NextATM_Click

End Sub

When I click on the command button, with this code in place, I get an error,
"Compile Error: Invalid qualifier"
I am using Access2K with Win2K.

Can anybody help?
Thanks,
Phil
 
D

Dirk Goldgar

Mary/Phil Stewart said:
I have a form with a command button. Which when clicked goes to the
next record. However, when it gets to a given record I want the
cursor to go a field other than the first one. The field I want to be
focused on is, "Page". Here is the code I am using:

Private Sub NextATM_Click()
On Error GoTo Err_NextATM_Click


DoCmd.GoToRecord , , acNext
Page.SetFocus

Exit_NextATM_Click:
Exit Sub

Err_NextATM_Click:
MsgBox Err.Description
Resume Exit_NextATM_Click

End Sub

When I click on the command button, with this code in place, I get an
error, "Compile Error: Invalid qualifier"
I am using Access2K with Win2K.

Can anybody help?
Thanks,
Phil

It seems likely that the problem is with the name "Page", which is a
reserved word and a property of the Form object. It's not a good idea
to use reserved words for your own objects and variables, as Access is
liable to misunderstand you. Either change the name of the control to
something else (e.g., "txtPage", if it's a text box), or use a more
explicit sytax to refer to it:

Me!Page.SetFocus

or even


Me.Controls("Page").SetFocus
 
C

Charanjeev Singh

Hi Phil,
I tried reproducing the behaviour with the Northwind
database. I created a new form and created a button with
the following code behind it.

Private Sub Command22_Click()
On Error GoTo Err_Command0_Click
DoCmd.GoToRecord , , acNext
CompanyName.SetFocus
Exit_Command22_Click:
Exit Sub
Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub

This is the only code in the form. And focus does go to
the CmopanyName as expected. Now the field name "Page" may
have something to do with this - try renaming the control
that displays the data for the "Page" field on the form t
something like say - txtPage and replace the line -

Page.SetFocus

WITH

txtPage.SetFocus

Best Regards,
Charanjeev Singh
Technical Consultant
Microsoft Access Developer Support
 
D

Dirk Goldgar

You normally need to refer to the form AND the field

Forms!(FormName).Page.SetFocus

Not, however, if the code is running behind the form containing the
control in question, which I take to be the case here. The name "Page"
is more likely to be the problem.
 

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

Similar Threads

Access Pop-Up Calendar 2
Code to open a query 2
acNext 3
Navigation Buttons 7
Check box question 2
Last Record Error 3
Compile error- Invalid use of property 2
Go to next record or close 1

Top