Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Navigation Buttons like - Next, Prev, First, New & so 3

Status
Not open for further replies.

Kenny2003

Technical User
Dec 29, 2002
53
GB
Hi gang,

Just spent most of today and all evening trying to get this to work and access keeps giving me a "Run Time error '2489' so before I tear all my hair out can any one suggest how to do what I need.

I am trying to write the code for Custom Navigation Buttons like - Next, Prev, First, New & so on.

I have a main form [frmMain] that is not bound to anything, it just acts as a holder for the sub-form and contains a couple of labels like the database name and so on.

On the main form is a sub-form [frmSub1] that is bound to the table that contains the actual data.

I want to have a set of buttons on the main unbound form that moves the records back or forth. To keep it simple, if we look at just the "next record" button.

I inserted a command button and on its "on click" property I have tried various code but none of it worked. I have searched all over the net but with no luck. I keep getting the same run-time error '2489' The Object '[Forms]![frmMain].[Form]![frmSub1]' isn't open? Below is a code sample so you know what I have tried to do so far.

Thank you in advance,

Kenny

------------------Code Begins-----------------------
Private Sub cmdGoToNext_Click()
DoCmd.GoToRecord acDataForm, "[Forms]![frmMain].[Form]![frmSub1]", acNext
End Sub
------------------Code Ends-------------------------
 
I just realised that I forgot to include the code I am currently using so here it is.

------------------Code Begins-----------------------
Private Sub cmdGoToNext_Click()
DoCmd.GoToRecord acDataForm, "[Forms]![frmMain].[Form]![frmSub1]", acNext
End Sub
------------------Code Ends-------------------------
 
Have you tried it without the quotes around "[Forms]![frmMain].[Form]![frmSub1]
 
How are ya Kenny2003 . . . . .

To resolve any error prompts (say 1st record has focus and you click previous), try this:
Code:
[blue][purple]Goto 1st:[/purple]
   Me![purple][b]subFormName[/b][/purple].SetFocus
   DoCmd.RunCommand acCmdRecordsGoToFirst
[purple]Goto Previous:[/purple]
   If Me![purple][b]subFormName[/b][/purple].Form.CurrentRecord > 1 Then
      Me![purple][b]subFormName[/b][/purple].SetFocus
      DoCmd.RunCommand acCmdRecordsGoToPrevious
   End If
[purple]Goto Next:[/purple]
   If Not Me![purple][b]subFormName[/b][/purple].Form.NewRecord Then
      Me![purple][b]subFormName[/b][/purple].SetFocus
      DoCmd.RunCommand acCmdRecordsGoToNext
   End If
[purple]Goto Last:[/purple]
   Me![purple][b]subFormName[/b][/purple].SetFocus
   DoCmd.RunCommand acCmdRecordsGoToLast
[purple][b]Goto New/Add:[/purple]
    Me![purple][b]subFormName[/b][/purple].SetFocus
   DoCmd.RunCommand acCmdRecordsGoToNew[/blue]

Calvin.gif
See Ya! . . . . . .
 
have a look at
thread702-918447

Hope this helps
Hymn
 
Hi Everyone,

As always, you guys are great. I appreciate all your suggestions and I have spent some time trying them all out but I still cant get it to work.

The problem I seem to be having is that the records I want to be able to navigate through are held on a sub-form. This sub-form is, in turn, held on a main form and I need the navigation buttons to be on this main form and not the sub.

So of course, when I set the buttons up as eveyone suggested, access cant find the records??

Any further suggestions ?

Regards,

Kenny
 
Hi, Kenny,

You tried AceMan's code and it didn't work? Because it looks like his syntax is just right. What is the name of your subform control and what is the name of your subform?

Ken S.
 
Kenny2003 said:
[blue] I have spent some time trying them all out but I still cant get it to work.[/blue]
Post the code for your Goto Previous button, as you have it now . . .

Calvin.gif
See Ya! . . . . . .
 
Hi Eupher,

Thanks for the reply.

The Sub-form control is called cmdGoToPrevious_Click()
The Sub-Form is called frmPlant_Sub1

I hope that this is the info you were asking for.

Regards,

Kenny
 
Hi TheAceMan,

Thanks, as always, for your reply and the code I am using for the 'on click' event of my "Go To Previous Record" cmd button is below.

The main form is called [frmPlant_Main]
The Sub-form is called [frmPlant_Sub1]
The command button is called cmdGoToPrevious

The button is on the main form and the sub form is used to display the records.

Thank again for your help.

Regards,

Kenny

-----------------------Code Begins---------------------
Private Sub cmdGoToPrevious_Click()
If Me!frmPlant_Sub1.Form.CurrentRecord > 1 Then
Me!frmPlant_Sub1.SetFocus
DoCmd.RunCommand acCmdRecordsGoToPrevious
End If
End Sub
-----------------------Code Ends-----------------------
 
Oh and I forgot to add that when I click on the button Access gives the following error:

Run-time error '2465':
Microsoft Access can't find the field 'frmPlant_Sub1' referred to in your expression.

then when I click debug Access highlights the following line of code in yellow:

If Me!frmPlant_Sub1.Form.CurrentRecord > 1 Then

Hope this helps.
 
quote Kenny2003. . . . . .

A name or spelling has to be wrong here . . .
[ol][li]Open the mainform in [blue]design view.[/blue][/li]
[li]Call up the properties for the form & click the Other Tab.[/li]
[li]Now click the the subform just inside its out line.[/li][/ol]
[purple]And the Name property is?[/purple]

Calvin.gif
See Ya! . . . . . .
 
Kenny,

You didn't quite answer my question (AceMan and I are after the same thing here). The name of the subform control is NOT the code behind the command button. When you place a subform on your form, you are placing a subform control. This control has a name which is NOT necessarily the same as the name of the object (the subform itself) to which the control is bound. If the two are named differently, you must refer to the name of the subform control on your form, not the name of the subform as it appears in the list of forms in the database window.

HTH,

Ken S.
 
Hi guys,

OK, the sub-form control name is Garden_Sub.

Is this where I am going wrong?

Kenny
 
DAMN Guys, It works !!!!!!!!!

Its like a weight has been suddenly lifted. This shows my lack of knowledge in Access matters. I did not know about the Sub-Form control name can be different to the actual sub-form name. I have learnt a big lession here and I want to thank you both.

Thank you, I really appreciate you guys taking time to help access newbies like me.

Regards,

Kenny
 
Kenny,

Same is true for *any* bound control. Glad you got it working. Gotta love those lightbulb moments. :)

Ken S.
 
Eupher said:
[blue] . . .Gotta love those lightbulb moments[/blue]
Yeaaaaaah . . . espcially when they transition from [silver]dim[/silver] to [fuchsia]Super NOVA![/fuchsia] ;-)

Calvin.gif
See Ya! . . . . . .
 
Indeed, but in my case its normally dim to dimmer but its YOU guys that make it a supernova :)
 
Can I be Cheeky and throw a wild card question at you guys, well two questions if I may be so bold.

As I have the custom navigation buttons working, I would like to add a record counter to display something like "Record 1 of 10". I have searched this forum before asking and the few posts I can find on the subject leave me with a headache - Is this a hard thing to do?

Is there a freeware or shareware app that you guys would recomend that will examine your code for unused code so that you can clean it up or remove it?

Now you guys have more than helped me out and I will not be offeneded if you do not reply, just thought I'd ask.

Kind regards,

Kenny
 
Actually let me update my question about record counters.

I have worked out the following code which I have placed in the subforms "on Current" event. It works fine except that when you open the form it says "Record 1 of 1" even though I have 12 records in the database. It only displays the correct number of records when you click on one of the navigation buttons. Any suggestions?

Regards,

Kenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top