Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005
    Posts
    1,191

    Unanswered: Custom Navigation Buttons

    So I'm creating a database for a client, and they've already got a system in place, they just want to go from a paper system to an electronic spiffy database system with all the trimmings. As such, they've already got the main id set up (the primary key) and they've got about 6000+ records already done on paper. They don't need these old records entered in the dB, but they do want to continue the numbering system.

    On a form in the database, then, I need to create navigation buttons that will select by ID instead of by record number like normal. I've attached a screenshot of what I've already got (I've left the Navigation Buttons property set to Yes for now just for comparison purposes as I'm creating these new ones). I've gotten everything to work just the same as the normal buttons except the text box part. I can't figure out how to allow the user to type in a number there and go to the matching record. Here's what I've got so far using the Lost Focus event, but this doesn't work:
    Code:
    Dim intRecNo As Integer
    intRecNo = Me.TxtBox_GoTo_NCM_No
    DoCmd.GoToRecord acDataForm, "Frm_NCM_View", acGoTo, intRecNo
    All the other buttons work exactly the same as the normal buttons, using code in the On Current property mostly. I just can't get this textbox part to work.

    Any ideas? Or does anyone know of a simpler method to use? Let me know if I have to explain something better.

    Thank you in advance to anyone who can help.
    Attached Thumbnails Attached Thumbnails Records.JPG  
    Me.Geek = True

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    For anyone with a similar problem, I've been able to make it work using the following code in the After Update event:
    Code:
    On Error GoTo Err_TxtBox_GoTo_NCM_No_AfterUpdate
    
    'Look if record exists
    Dim RecNo As String, strRec As String, lngRec As Long
    strRec = CStr(Me.TxtBox_GoTo_NCM_No)
    lngRec = CLng(Me.TxtBox_GoTo_NCM_No)
    RecNo = Nz(DLookup("[Fld_NCM_No]", "Tbl_NCM", "[Fld_NCM_No] = " & strRec), "0")
    
    'Error msg if record does not exist
    If RecNo = "0" Then
        MsgBox "NCM does not exist.", vbCritical, "Invalid Entry"
        Me.TxtBox_GoTo_NCM_No = Me.Fld_NCM_No
        Exit Sub
    'Else go to record
    Else
        DoCmd.GoToRecord , , acGoTo, lngRec - 6380
        Exit Sub
    End If
    
    Exit_TxtBox_GoTo_NCM_No_AfterUpdate:
        Exit Sub
    
    Err_TxtBox_GoTo_NCM_No_AfterUpdate:
        Me.TxtBox_GoTo_NCM_No = Me.Fld_NCM_No
        Exit Sub
    This solution only works because the primary id is still incremental, just offset by 6380. It references the field "Fld_NCM_No", which is displayed elsewhere on the form.

    For anyone doing something similar, the code I used in the On Current event of the form was
    Code:
    Me.TxtBox_Record_Count = "Record " & Me.CurrentRecord & _
         " of " & DCount("*", "Tbl_NCM")
    Me.TxtBox_GoTo_NCM_No = Me.Fld_NCM_No
    
    If Me.CurrentRecord = 1 Then
        Me.CmdBtn_GoTo_Previous.Enabled = False
    Else
        Me.CmdBtn_GoTo_Previous.Enabled = True
    End If
    
    If Me.CurrentRecord = DCount("*", "Tbl_NCM") Then
        Me.CmdBtn_GoTo_Next.Enabled = False
    Else
        Me.CmdBtn_GoTo_Next.Enabled = True
    End If
    The code behind the four buttons are something like
    Code:
    DoCmd.GoToRecord , , acFirst
    If someone wants, I can post a sample dB to the Code Bank upon request.
    Attached Thumbnails Attached Thumbnails Records.JPG  
    Me.Geek = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •