Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

State of a text box and use of "f2" key to begin editing

Status
Not open for further replies.

mike777

Programmer
Jun 3, 2000
387
US
Here my code:
Code:
Private Sub SaveRecord_Click()
If Me.Dirty = True Then
    DoCmd.RunCommand acCmdSaveRecord
    WavFileName = "c:\windows\mywav.wav"
    x = sndPlaySound(WavFileName, &H0)
End If
DoCmd.GoToControl "tb_answer"
SendKeys "{f2}", True
End Sub
The problem is Access is doing everything correctly except that when I use the access key (Alt + S) to activate the "Save Record" command button, it sends the "F2" key to the Access application and not the field that is supposed to be prepared for editing, so that a dialog box pops up asking the user what name they want to save the form to (it's a "Save Form As" dialog box).
Question: Is there a better way to set the state of a field from having its entire contents selected to having the cursor positioned at the end of the contents (it's a memo field) so the user can immediately start editing instead of having to hit "f2" themselves?
Thanks for your help.
 
substitute this
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
for yours
DoCmd.RunCommand acCmdSaveRecord


DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
You should never ned to use sendkeys.

Even when you think there is no alternative .... there is.

In this case when you just want to select the text in a field :

copy the subroutine to a module.

Public Sub Seltext(frmForm As Form, strControlName As String)
Dim ctlControl As Control

Set ctlControl = frmForm.Controls(strControlName)

ctlControl.SelStart = 0
ctlControl.SelLength = Len(ctlControl.Text)

End Sub


Now to select the text in your field:

Call SelText(Me, b_answer.name) instead of SendKeys "{f2}", True

Also, use SetFocus instead of GotoControl so:

b_answer.SetFocus

Why, it's less typing :)

Bill Paton
william.paton@ubsw.com
Check out my website !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top