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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox Events

Status
Not open for further replies.

polnichek

Technical User
Dec 13, 2005
35
CA
I have an application that has a datasheet presentation style for the data entry form (client insisted on this) and I have a need for a field that can handle two events. I need it to do one thing on double click and a different thing on key down all within the same field. I have tried to simply define two events in the same text box in design view but when a user uses tab to tab into the field the key down event fires without having the keydown key even being pressed. Essentially I need the user to be able to tab into the field and use the double click event to search the column for data, or use the key down event to open a second form to enter new data, or alternatively to tab out of the field and do nothing. I hpe I have explained the problem sufficiently and if anyone has a solution I would greatly appreciate it.

Regards,

Polnichek
 
Are you writing your events within VBA or are you using the macro builder?



-Pete
 
What key stroke do you want the user to use to open the form? The keydown event has a key_code and shift parameter which you can use to destinguish a tab key from other keys.
 
Thank you both for your replies. In answer to Pete's question I had been using the macro builder. But if I used visual basic code can I directly reference the event handler? For example could I set up an IF statement that did something like:
IF KeyDown
DoCmd.open "frmCompanyDataEntry",,acNew
ELSEIF DblClick
DoCmd.OpenQuery "GetDataSheetRec"
end if

I know the syntax is not completely correct but I did not realize you could specify the event handler directly.
Regards,

David
 
In response to ddiamond's reply:
I will do a little research on the parameters of the Key Down event. I imagine you would have to use visual basic code for this and I will try to figure that one out. As I indicated to Pete I had been using the Macro Builder to get this done, so now it is becoming apparent I should use code.

If you have a suggestiuon for a tutorial or a book on this I would greatly appreciate it.

Thanks again,

David
 
David,

Depending upon the name of your textbox control your keydown would be something like this
Code:
Private Sub txtNew_KeyDown(KeyCode As Integer, Shift As Integer)
    If <> KeyCode = 9 Then
        DoCmd.Open "frmCompanyDataEntry",,acNew
    End If
End Sub

and your double click
Code:
Private Sub txtNew_DblClick(Cancel As Integer)
    DoCmd.OpenQuery "GetDataSheetRec"
End Sub

-Pete
 
im sorry...i posted incorrectly

change:
Code:
If <> Keycode = 9 Then
to
Code:
If Keycode <> 9 Then


-Pete
 
Thank you Pete I will give that a try and see if I can make it happen! I had no idea I would get answers this fast. I appreciate it a great deal.

Regards,

David
 
Thank you both Pete and ddiamond. By switching to code instead of the macro builder you helped me resolve my problem. The datasheet form now has the behaviour I need. This only means of course I am going to get stuck on something else....

Thanks again,

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top