Code I don't Understand

  • Thread starter Thread starter Mary/Phil Stewart
  • Start date Start date
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
 
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
 
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
 
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.
 
Back
Top