Personalized record navigation buttons

  • Thread starter Thread starter Vítor Barbosa
  • Start date Start date
V

Vítor Barbosa

Hi all,

I'm having some difficulties to solve a problem:

1) I have 3 forms: Main > Internamentos > sbfrmBotõesNavegação
2) Internamentos is a Main subform that uses sbfrmBotõesNavegação as a
record navigation buttons, like Stephen Lebans do with this sample:
http://www.lebans.com/recnavbuttons.htm
3) My problem is that the original code works when Internamentos is opened
as main form but not when it is opened as a subform of Main
4) My Next button code, for example looks like this:

----------------------------
Private Sub btnSeguinte_Click()
On Error GoTo Err_btnSeguinte_Click

If adhIsSubForm(Me.Parent) = False Then
DoCmd.GoToRecord acDataForm, Me.Parent.name, acNext
Else
On Error Resume Next

Forms(Me.Parent.Parent.name).Controls(Me.Parent.name). _
Form.Recordset.MoveNext
On Error GoTo Err_btnSeguinte_Click
End If

Exit_btnSeguinte_Click:
Exit Sub

Err_btnSeguinte_Click:
MsgBox Err.Description
Resume Exit_btnSeguinte_Click

End Sub
----------------------------


PS: adhIsSubForm is a function that checks if Internamentos is a subform or
a form

5) My error occurs here:

Forms(Me.Parent.Parent.name).Controls(Me.Parent.name). _
Form.Recordset.MoveNext

6) What's the problem?

TIA,

Vítor Barbosa
(Portugal) www.euro2004.com
 
Hi,

Problem solved. My error was so simple but yet so hard to find.
My subform/subreport control was named "sbfrmInternamentos" and it should be
"Internamentos". Now it works!

Bye, Vítor Barbosa
 
Glad you got the sample working!
Vitor did you have to change any of the code/logic to get the RecNav
Subform to work on your SubForm?

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Thanks Vitor!
For some reason I cannot download the attachment. Could you Email it to
me?

I'm away on business for the next 4 days but will post your mods to my
site when I return.
:-)

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Vítor Barbosa said:
Hi Stephen,


Yes, I did.

1) Added this Funcion:

*****************
Public Function adhIsSubForm(frm As Form) As Boolean
' Is the form referenced in the
' parameter currently loaded as a subform?
' Check its Parent property to find out.

' From Access 2000 Developer's Handbook, Volume I
' by Getz, Litwin, and Gilbert (Sybex)
' Copyright 1999. All rights reserved.

Dim strName As String
On Error Resume Next
strName = frm.Parent.name
adhIsSubForm = (Err.Number = 0)
Err.Clear
End Function
*********************

2) Changed the code in your's record navigation form:

*******************************
Option Compare Database
Option Explicit

' Copyright
' Stephen Lebans
' www.lebans.co
' 06-2004: Changed by Vítor Barbosa as suggested by Luiz Cláudio

Private Sub btnIrParaPrimeiro_Click()
On Error GoTo Err_btnIrParaPrimeiro_Click

If adhIsSubForm(Me.Parent) = False Then
DoCmd.GoToRecord acDataForm, Me.Parent.name, acFirst
Else
On Error Resume Next

Forms(Me.Parent.Parent.name).Controls(Me.Parent.name).Form.Recordset.Mov
eFir
st
On Error GoTo Err_btnIrParaPrimeiro_Click
End If

Exit_btnIrParaPrimeiro_Click:
Exit Sub

Err_btnIrParaPrimeiro_Click:
MsgBox Err.Description
Resume Exit_btnIrParaPrimeiro_Click

End Sub
Private Sub btnIrParaÚltimo_Click()
On Error GoTo Err_btnIrParaÚltimo_Click

If adhIsSubForm(Me.Parent) = False Then
DoCmd.GoToRecord acDataForm, Me.Parent.name, acLast
Else
On Error Resume Next

Forms(Me.Parent.Parent.name).Controls(Me.Parent.name).Form.Recordset.Mov
eLas
t
On Error GoTo Err_btnIrParaÚltimo_Click
End If

Exit_btnIrParaÚltimo_Click:
Exit Sub

Err_btnIrParaÚltimo_Click:
MsgBox Err.Description
Resume Exit_btnIrParaÚltimo_Click

End Sub

Private Sub btnSeguinte_Click()
On Error GoTo Err_btnSeguinte_Click

If adhIsSubForm(Me.Parent) = False Then
DoCmd.GoToRecord acDataForm, Me.Parent.name, acNext
Else
On Error Resume Next
Forms(Me.Parent.Parent.name). _
Controls(Me.Parent.name).Form.Recordset.MoveNext
On Error GoTo Err_btnSeguinte_Click
End If

Exit_btnSeguinte_Click:
Exit Sub

Err_btnSeguinte_Click:
MsgBox Err.Description
Resume Exit_btnSeguinte_Click

End Sub

Private Sub btnAnterior_Click()
On Error GoTo Err_btnAnterior_Click

If adhIsSubForm(Me.Parent) = False Then
DoCmd.GoToRecord acDataForm, Me.Parent.name, acPrevious
Else
On Error Resume Next

Forms(Me.Parent.Parent.name).Controls(Me.Parent.name).Form.Recordset.Mov
ePre
vious
On Error GoTo Err_btnAnterior_Click
End If


Exit_btnAnterior_Click:
Exit Sub

Err_btnAnterior_Click:
MsgBox Err.Description
Resume Exit_btnAnterior_Click

End Sub


Private Sub txtRegistoActual_AfterUpdate()
Dim intRegistoActual As Integer

intRegistoActual = Nz(Me.txtRegistoActual.Value, 0)
If intRegistoActual <> 0 Then
If adhIsSubForm(Me.Parent) = False Then
DoCmd.GoToRecord acDataForm, Me.Parent.name, acGoTo,
Me.txtRegistoActual.Value
Else
On Error Resume Next
DoCmd.GoToRecord , Forms(Me.Parent.Parent.name), acGoTo,
Nz(Me.txtRegistoActual.Value, Me.CurrentRecord)
End If
ElseIf intRegistoActual = 0 Then
MsgBox "Insira o número do registo para o qual deseja ir!",
vbInformation, "Aviso..."
End If

Me.txtHidden.SetFocus
End Sub


Public Sub EnableDisableButtons()
Dim intRegistoActual As Integer

' Copyright
' Stephen Lebans
' www.lebans.co

Me.txtRegistoActual.Value = Me.Parent.CurrentRecord
' If lblNumRecords is blank then this is the
' first time through and the recordset pointers
' may not be updated yet. We need to allow time
' for them to get updated.
If Me.lblNumRecords.Caption = "" Then
Me.Parent.RecordsetClone.MoveLast
DoEvents
End If
Me.lblNumRecords.Caption = "de " & Me.Parent.RecordsetClone.RecordCount
DoEvents

' Are we on a NEW record
If Me.Parent.NewRecord = True Then
' Update our nav info.
With Me
.txtRegistoActual.Value =
Me.Parent.RecordsetClone.RecordCount +
 
Hi Stephen,
I've already email my db to you.

With the best compliments,
Vítor Barbosa
 
Back
Top