If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Create DELETE command button

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-31-12, 14:52
capesteve capesteve is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
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"
Else
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.
Reply With Quote
  #2 (permalink)  
Old 01-31-12, 15:07
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
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)
else
mycontrol = ""
endif

you coudl push that into a function
eg
function DeleteChar(strValue) as string
if len (strValue) > 1 then
strValue = left(strValue, len(strValue)-1
else
strValue = ""
endif
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


eg

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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 02-02-12, 17:39
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
This code allows for the Command Button to do this for any Textbox on the Form, without hard-coding it for a given Control:
Code:
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
Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003

Last edited by Missinglinq; 02-02-12 at 17:51.
Reply With Quote
Reply

Tags
command buttons

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On