PC Review


Reply
Thread Tools Rate Thread

Code I don't Understand

 
 
Mary/Phil Stewart
Guest
Posts: n/a
 
      10th Feb 2004
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


 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      10th Feb 2004
"Mary/Phil Stewart" <(E-Mail Removed)> wrote in message
news:5abWb.141990$U%5.647004@attbi_s03
> 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

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Charanjeev Singh
Guest
Posts: n/a
 
      10th Feb 2004
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

>-----Original Message-----
>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
>
>
>.
>

 
Reply With Quote
 
Guest
Posts: n/a
 
      11th Feb 2004
You normally need to refer to the form AND the field

Forms!(FormName).Page.SetFocus
>-----Original Message-----
>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
>
>
>.
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      11th Feb 2004
<(E-Mail Removed)> wrote in message
news:dbf601c3f03a$b3bf1640$(E-Mail Removed)
> 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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I am trying to understand this code... Henry Stock Microsoft Frontpage 3 27th Jul 2008 08:59 PM
Please. Help me understand this code Viper Microsoft Access 4 29th Jan 2007 07:59 PM
Help - Can't understand Code =?Utf-8?B?QW5nZWxpbmU=?= Microsoft Access Forms 8 29th Mar 2006 12:36 PM
Don't Understand Code miracleblake Microsoft Excel Discussion 3 8th Dec 2005 08:12 PM
Help me understand this code Carrot Microsoft Excel Misc 2 14th Oct 2005 06:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 PM.