Thread: Create DELETE command button
01-31-12, 14:52 #1Registered User
- 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"
newTxtVal = txtVal & "A"
Me![FIRSTNAME].Value = newTxtVal
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.
01-31-12, 15:07 #2Jaded Developer
Provided Answers: 59
- Join Date
- Nov 2004
- out on a limb
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
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
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 youI'd rather be riding on the Tiger 800 or the Norton
02-02-12, 17:39 #3Moderator
Provided Answers: 19
- Join Date
- Jun 2005
- Richmond, Virginia USA
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) Screen.PreviousControl.SetFocus End If Err_BackSpace_Click: Resume Next End Sub
Last edited by Missinglinq; 02-02-12 at 17:51.Hope this helps!
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007