Navigation Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a subform. The subform object has navigation buttons.
What is the code that is actually occuring when you click the next arrow or
the go to last record arrow. I am asking because I would like more control
of which record to move to.

Thank you for your help.

Steven
 
Hi Steven,

here is some navigation code you can use -- thes procedures
would go into a general module

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'------------------------------------ RecordFirst
Function RecordFirst()
'example useage: OnClick event
'of a Go To First Record command button
' = RecordFirst()
On Error GoTo RecordFirst_error
DoCmd.RunCommand acCmdRecordsGoToFirst
Exit Function
RecordFirst_error:
MsgBox Err.Number & " " & Err.Description _
, , "Cannot go to first record right now"
End Function

'------------------------------------ RecordPrev
Function RecordPrev()
'example useage: OnClick event
'of a Go To Previous Record command button
' = RecordPrev()
On Error GoTo RecordPrev_error
DoCmd.RunCommand acCmdRecordsGoToPrevious
Exit Function
RecordPrev_error:
MsgBox Err.Number & " " & Err.Description _
, , "Cannot go to previous record right now"
End Function

'------------------------------------ RecordNext
Function RecordNext()
'example useage: OnClick event
'of a Go To Next Record command button
' = RecordNext()
On Error GoTo RecordNext_error
DoCmd.RunCommand acCmdRecordsGoToNext
Exit Function
RecordNext_error:
MsgBox Err.Number & " " & Err.Description _
, , "Cannot go to next record right now"
End Function

'------------------------------------ RecordLast
Function RecordLast()
'example useage: OnClick event
'of a Go To Last Record command button
' = RecordLast()
On Error GoTo RecordLast_error
DoCmd.RunCommand acCmdRecordsGoToLast
Exit Function
RecordLast_error:
MsgBox Err.Number & " " & Err.Description _
, , "Cannot go to last record right now"
End Function

'------------------------------------ RecordNew
Function RecordNew()
'example useage: OnClick event
'of a New Record command button
' = RecordNew()
On Error GoTo RecordNew_error
'if there have been changes to the current record,
'save them
If Screen.ActiveForm.Dirty Then
Screen.ActiveForm.Dirty = False
end if
DoEvents
DoCmd.RunCommand acCmdRecordsGoToNew
Exit Function
RecordNew_error:
If Err.Number = 2046 Then
'You are already on a new record
Exit Function
End If
MsgBox Err.Number & " " & Err.Description _
, , "Cannot go to a new record right now"
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Crystal,

Thank you for your help.

One last question. Can I be in a different obect on the mainform and call
the RecordFirst so the Subform goes to the first record.

The form is MainForm01 with objects Textbox01 and Subform01. The situation
is lets say I am on the 40th record in Subform01. When I click to Textbox01
I want Subform01 to go back to the 1st record using your code.

Thank you again very much for your help.

Steven
 
I might need to explain that more. I do not want to put the code on the
OnExit of object SubForm01 because there are other objects on MainForm01 that
when I move to them I want SubForm01 to not change. I only want SubForm01 to
go to the FirstRecord if I click to TextBox01.

Thank you.

Dutch
 
Hi Steven,

in that case, you can do this:

Me.subform_controlname.Form.Recordset.MovePrevious

Me.subform_controlname.Form.Recordset.MoveNext

Me.subform_controlname.Form.Recordset.MoveFirst

Me.subform_controlname.Form.Recordset.MoveLast

Me.subform_controlname.Form.Recordset.AddNew

If you have a specific record you want to find in the
subform, you can use, for instance:

'~~~~~~~~~~~~~~~~~~~
Me.subform_controlname.Form.RecordsetClone.FindFirst
"IDfield= 9999"

If Not Me.subform_controlname.Form.RecordsetClone.NoMatch Then
Me.subform_controlname.Form.Bookmark = _
Me.subform_controlname.Form.RecordsetClone.Bookmark

End If

'~~~~~~~~~~~~~~~~~~~

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
you can specifically move to the first record of any form or
subform or subsubform using the appropriate statement:

forms!formname.Recordset.findfirst

forms!formname.subform_controlname.Form.Recordset.findfirst

forms!formname.subform_controlname.Form.subsubform_controlname.Form.Recordset.findfirst

Whenever possible, use "Me." to make a relative, instead of
absolute, reference

you can use Me.parent (Me.parent.parent, etc) to refer to
the next form up the chain

so, to refer to subform2 from subform1:

Me.parent.subform2_controlname.form


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Crystal,

I dont get it. I have a main form Employees001 that has a textbox named
Text08 and a subform named Child2. Child2 has a Source Object from form
Employees002.

I tried this on the OnEnter of Text08 and got an error Application Defined
or Object Defined error:

If IsNull(Me.Text08) = True Then
Me.Child2.Form.RecordSet.MoveFirst
Endif

So since that gave me an error I tried this. It did not error but it did
not move either:

If IsNull(Me.Text08) = True Then
Me.Child2.Form.RecordSetClone.MoveFirst
Endif

Can you help me once more please.

Thank you,

Steven
 
Hi Steven

of course :)

first, to make me happy, do this:

change the NAME property of Child2 to something logical,
like --> subEmployees

(View, Properties from the menu -- Name is the top property
on the ALL tab for whatever control is selected)

make a command button on your mainform:

Name --> cmdMoveFirstSub
OnClick --> [Event Procedure]
'~~~~~~~~~~~
Me.subEmployees.Form.RecordSet.MoveFirst
'~~~~~~~~~~~

you should ALWAYS change the name property after you create
controls so they make sense and are not ambiguous

You can't refer to the subform as a subform on the ENTER
event because you are already on it and now it is the form ...

I do not understand why you were using a textbox to do this
other than ... you are still learning (and there is nothing
wrong with that <g> )

What does "Text08" represent?

(I trust you will give it a better name)


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Crystal,

Text08 is so when the form opens subEmployees has 1,500 employees. If I
type Stev then subEmployees will query as I type each character in Text08
and I will get my name an another Steven and someone with a last name of
Stevens etc. so I can access that person faster.

On to the other part:

I still get the "Application Defined or Object Defined Error"

I have noticed when I type Me.subEmployees.Forms. that at this point
recordset is not an option. Recordsetclone is and some other things but not
recordset. I think that is why I get the error.

Steven
 
Hi Steven,

even though it is not an option, you can use it ... the list
does not contain everything ;)

that is not what is causing the problem...if your subform
has a RecordSource, you can use RecordSet

Me.subEmployees.Forms. --> NO! just Form -- not plural


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Back
Top