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 gkittelson 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 - Go To Record Option

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have created custom navigation buttons at the top of the form at the user's request. I have all of the buttons working and "Record X of X" is working. However, I am having a problem getting the "Go to Record" to work.
I have a textbox that the user can enter the record they want to go to. I tried OnAfterUpdate .Move, but can't seem to get the syntax right. I tried to use the example in Help, but had syntax issues again.
 
Add this code to the LostFocus property of the control you use to allow the user to input a record number.

Dim i

i = Forms!formname!ctlname.Value
DoCmd.GoToRecord acDataForm, "formname", acGoTo, i
End Sub

where formname = the name of your form and
ctlname = the name of the textbox that the user inputs the record number into.

Hope this helps...

jjones@cybrtyme.com
 
Hi!

Here is my variant of custom record navigator.
Controls:
txtTypeUnitCount - textbox for show record count (disabled)
Data Source =&quot;(of &quot; & IIf([txtCurrentRecord]<=DCount(&quot;TypeUnitNo&quot;;&quot;XUNA&quot;);DCount(&quot;TypeUnitNo&quot;;&quot;XUNA&quot;);[txtCurrentRecord]) & &quot;)&quot;
&quot;XUNA&quot; - my table (form record source is based on this table)

txtCurrentRecord - textbox for show current record (enabled)
Unbound
Label Caption - Go to record:

Both textboxes I put alongside.

Codes:

Private Sub Form_Current()
Me.txtCurrentRecord = Me.CurrentRecord
End Sub

'------------------------------
Private Sub txtCurrentRecord_AfterUpdate()
On Error GoTo Err_txtCurrentRecord_AfterUpdate
Dim rst As Recordset
Dim lngRecordCount As Long
Dim lngCurrentRecord As Long

lngCurrentRecord = Me.CurrentRecord
Set rst = Me.RecordsetClone
lngRecordCount = rst.RecordCount

If Me.txtCurrentRecord <> Me.CurrentRecord Then
Select Case Me.txtCurrentRecord
Case Is <= 0
Me.txtCurrentRecord = 1
Case Is > lngRecordCount
If Me.NewRecord Then
Me.txtCurrentRecord = lngCurrentRecord
Else
Me.txtCurrentRecord = lngRecordCount
End If
End Select
If Me.txtCurrentRecord <> Me.CurrentRecord Then
DoCmd.GoToRecord , , acGoTo, Me.txtCurrentRecord
End If
End If
rst.Close
Set rst = Nothing

Exit_txtCurrentRecord_AfterUpdate:
Exit Sub

Err_txtCurrentRecord_AfterUpdate:
If Err.Number = 2105 Then
Resume Next
Else
MsgBox &quot;Error No &quot; & Err.Number & vbLf & Error$, , Me.Name & &quot; Sub txtCurrentRecord_AfterUpdate&quot;
Resume Exit_txtCurrentRecord_AfterUpdate
End If

End Sub


I hope its would help you.
Aivars

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top