Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012

    Unanswered: Create DELETE command button

    Using Access 2003, I am working on a touch screen input form. I was able to find the following code to create the individual letter buttons to input a name in the field which works great:

    Private Sub commandA_Click()

    Dim txtVal As String
    Dim newTxtVal As String

    If IsNull(Me![FIRSTNAME].Value) Then
    Me![FIRSTNAME].Value = "A"
    txtVal= Me![FIRSTNAME].Value
    newTxtVal = txtVal & "A"
    Me![FIRSTNAME].Value = newTxtVal
    End If

    End Sub

    I would like to create a DELETE button to allow the user, when clicked, to delete the last letter in the field if they make a mistake but not being a VB coder by any means I'm not sure what to modify or to write in code. Any suggestions would be great. Thanks.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    I forget which but you need to examine the various properties of the control
    .text and / .value get set at different times

    if it was .text that has the current code then

    if len (mycontrol) > 1 then
    mycontrol.text = left(mycontrol, len(mycontrol)-1)
    mycontrol = ""

    you coudl push that into a function
    function DeleteChar(strValue) as string
    if len (strValue) > 1 then
    strValue = left(strValue, len(strValue)-1
    strValue = ""
    DeleteChar = strValue
    end function

    then call that function from the relevant event(s)
    eg say you had a control called tbusername
    in the on change event you'd store the fact that the user was last using tbusername, in say strLastControlUsed
    then when they press the back button call the function with the relevant vlaues


    in the back button controls on click event

    select case strLastControlUsed
    case = "tbusername"
    tbusername.text = DeleteChar(tbusername.text)
    case = "tbserialno"
    tbserialno.text = DeleteChar(tbserialno.text)
    default ="" 'do nothing
    end select

    bear in mind you'd be smarter to use an enumeration as its probably better self documenting
    or you could use the value of the variable and do away with the select
    you'd need to preset the last used control each and every time the user selects something either to a control name or nothing so you don't delete characters off the last used column when you'd moved onto another control in the mean time. if your users can fidn a way to destroy your program logic they will.
    you will need to evolve your design say to handle radio buttons, check boxes and so on. stuff them into a collection along witht he old value.. up to you
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    This code allows for the Command Button to do this for any Textbox on the Form, without hard-coding it for a given Control:
    Private Sub BackSpace_Click()
     On Error GoTo Err_BackSpace_Click
    If Len(Screen.PreviousControl.Value) > 0 Then
      Screen.PreviousControl.Value = Left(Screen.PreviousControl.Value, Len(Screen.PreviousControl.Value) - 1)
     End If
    Resume Next
    End Sub
    Linq ;0)>
    Last edited by Missinglinq; 02-02-12 at 17:51.
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Tags for this Thread

Posting Permissions

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