Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2013
    Posts
    20

    Question Unanswered: Set Focus on field you click

    I am trying to use a number pad code to pop up and enter the numbers you pick. Here is the code I found. I added the "."

    Option Compare Database
    Option Explicit

    Sub AddDigit(NewDigit As String)
    If Len(Me.SSN & NewDigit) <= 9 Or Len(Me.SSN & NewDigit) = "." Then
    Me.SSN = Me.SSN & NewDigit
    End If
    End Sub

    Private Sub cmdBksp_Click()
    On Error GoTo Err_cmdBksp_Click
    If Not IsNull(Me.SSN) Then
    If Len(Me.SSN) - 1 < 1 Then
    SSN = Null
    Else
    Me.SSN = Left(Me.SSN, Len(Me.SSN) - 1)
    End If
    End If
    Exit_cmdBksp_Click:
    Exit Sub

    Err_cmdBksp_Click:
    MsgBox Err.Description
    Resume Exit_cmdBksp_Click

    End Sub

    Private Sub cmd1_Click()
    On Error GoTo Err_cmd1_Click

    Call AddDigit("1")

    Exit_cmd1_Click:
    Exit Sub

    Err_cmd1_Click:
    MsgBox Err.Description
    Resume Exit_cmd1_Click

    End Sub
    Private Sub cmd2_Click()
    On Error GoTo Err_cmd2_Click

    Call AddDigit("2")

    Exit_cmd2_Click:
    Exit Sub

    Err_cmd2_Click:
    MsgBox Err.Description
    Resume Exit_cmd2_Click

    End Sub

    Private Sub cmd3_Click()
    On Error GoTo Err_cmd3_Click

    Call AddDigit("3")

    Exit_cmd3_Click:
    Exit Sub

    Err_cmd3_Click:
    MsgBox Err.Description
    Resume Exit_cmd3_Click

    End Sub
    Private Sub cmd4_Click()
    On Error GoTo Err_cmd4_Click

    Call AddDigit("4")

    Exit_cmd4_Click:
    Exit Sub

    Err_cmd4_Click:
    MsgBox Err.Description
    Resume Exit_cmd4_Click

    End Sub
    Private Sub cmd5_Click()
    On Error GoTo Err_cmd5_Click

    Call AddDigit("5")

    Exit_cmd5_Click:
    Exit Sub

    Err_cmd5_Click:
    MsgBox Err.Description
    Resume Exit_cmd5_Click

    End Sub
    Private Sub cmd6_Click()
    On Error GoTo Err_cmd6_Click

    Call AddDigit("6")

    Exit_cmd6_Click:
    Exit Sub

    Err_cmd6_Click:
    MsgBox Err.Description
    Resume Exit_cmd6_Click

    End Sub
    Private Sub cmd7_Click()
    On Error GoTo Err_cmd7_Click

    Call AddDigit("7")

    Exit_cmd7_Click:
    Exit Sub

    Err_cmd7_Click:
    MsgBox Err.Description
    Resume Exit_cmd7_Click

    End Sub
    Private Sub cmd8_Click()
    On Error GoTo Err_cmd8_Click

    Call AddDigit("8")

    Exit_cmd8_Click:
    Exit Sub

    Err_cmd8_Click:
    MsgBox Err.Description
    Resume Exit_cmd8_Click

    End Sub
    Private Sub cmd9_Click()
    On Error GoTo Err_cmd9_Click

    Call AddDigit("9")

    Exit_cmd9_Click:
    Exit Sub

    Err_cmd9_Click:
    MsgBox Err.Description
    Resume Exit_cmd9_Click

    End Sub
    Private Sub cmd0_Click()
    On Error GoTo Err_cmd0_Click

    Call AddDigit("0")

    Exit_cmd0_Click:
    Exit Sub

    Err_cmd0_Click:
    MsgBox Err.Description
    Resume Exit_cmd0_Click

    End Sub

    Private Sub Command19_Click()
    Call AddDigit(".")

    Exit_cmd1_Click:
    Exit Sub

    Err_cmd1_Click:
    MsgBox Err.Description
    Resume Exit_cmd1_Click
    End Sub

    Now how can I replace the SSN field with a field that you click so I don't have to duplicate this for every field that I input numbers?????

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Use a global variable in the form, declare it as a control. Eg
    Code:
    dim selectedcontrol as control
    in each relevant controls setfocus event store the name of that control in that variable. Eg
    Code:
    selectedcontrol = ssn
    then change your code so that instead of referring to me.ssn, refer to the variable. Eg
    Code:
    selectedcontrol.text = selectedcontrol & newdigit
    You will need to add some code to test if the variable has been set before trying to add a digit
    you will also need to think of a way to disable the whole keypad so it only works for the period of time you want it to
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    A suggestion when posting code please make certain you post code here inside the [ c o d e ] and [ / c o d e ] tags. Remove the spaces so [ / c o d e ] becomes [code]
    It make you code easier to read
    please indent your code so at each level of nesting it steps in by, say, two spaces, again for legibility
    also please resist the temptation to post all of your code. If you pist cide that isnt relevant to the question it just annoys some contributors and may discourage them from responding. Unthinkingky pisting all code sends out an implicit message that your time is too important to work out wgat us relevant but respondants tine isnt as they have to wade through whatever to diagnose the fault. Again code legibility helps encourage people to respond to the problem

    a final comment before reaching for help on forums consider using the help system or google to see if there is a fix within your grasp. Im pretty certain either if those would have suggested the setfocus event
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Oct 2013
    Posts
    20
    Thanks for the help and suggestions. As far as the other comment. I am a novice to access. I always go to google for the first step but I joined forums to help me see the inherited problems that could arise from just thinking simplistic. Take your reply to the message. The comment that you made as far as stopping the input made me realize that I need to create a field on the num pad and just copy to the field I needed with a enter button. I rely on the pros to help with the consequences of my novice actions. I will do my part to create better posts. I hope you will do your part and help novices avoid the pitfalls of their actions. Thanks again for your help.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    No problem matey
    re reading my post there may be interpreted an almost passive aggresive tone. If so its not meant.
    Every one has got start somewhere, its no problem hence a few suggestions. Theres no demands or expectations of contributors to these or other forums.

    glad it helped
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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