Use the enter key to make a selection

D

Damien McBain

Hi All,

I have a form which displays continuous forms based on some search results.
I have an "OnDoubleClick" event which copies some information from the
selected record back to another form.

Rather than use the double click event, I want to allow the user to press
enter when the required record has the focus and achieve the same result as
double clicking. How do I do this?

I have read the F1 information on "OnKeyPress" but I don't understand how to
translate that to what I want to achieve.

Damo
 
D

Damien McBain

Damien said:
Hi All,

I have a form which displays continuous forms based on some search
results. I have an "OnDoubleClick" event which copies some
information from the selected record back to another form.

Rather than use the double click event, I want to allow the user to
press enter when the required record has the focus and achieve the
same result as double clicking. How do I do this?

I have read the F1 information on "OnKeyPress" but I don't understand
how to translate that to what I want to achieve.

Damo


OK I made it work by doing this:

Private Sub CustName_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo AwwwShit
'===============================

Dim strCharacter As String
Dim daNumba
Dim daName

strCharacter = Chr(KeyCode)
If strCharacter = Chr(13) Then
daNumba = CustNo
daName = CustName
DoCmd.Close
Forms!frmDataEntry!ICust.SetFocus
Forms!frmDataEntry!ICust = daNumba
Forms!frmDataEntry!CustLookup.SetFocus
Forms!frmDataEntry!CustLookup = daName
Forms!frmDataEntry!IRequiredDAte.SetFocus
Else
End If

'===============================
gtfo:
Exit Sub
AwwwShit:
MsgBox Err.Description, , "F.A.C.T.S."
End Sub

Is that the bext way to do it? I suppose I could use case if there were
multiple keys I wanted to assign commands to.
 
B

Brendan Reynolds

You can simplify it a bit using the built-in keycode constants ...

If KeyCode = vbKeyReturn Then

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
D

Damien McBain

Brendan said:
You can simplify it a bit using the built-in keycode constants ...

If KeyCode = vbKeyReturn Then

thanks Brendan....this is new ground for me
 
D

Damien McBain

Brendan a while back you posted an answer to one of my questions about how
to test for the existence of a record in a given table. You posted some code
from Northwind. I have tried to manipulte it but I can't get it to work.
This is my (not working) code as stands:

Private Sub ICust_AfterUpdate()
On Error GoTo AwwwShit
===============================
Dim rst As ADODB.Recordset
Dim fnd As Boolean
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.Open "SELECT CustNo(*) AS CstNo FROM tblCustomers WHERE CustNo <>
0"
fnd = .Fields("CstNo") <> 0
.Close
End With
If fnd Then
CustLookup = cboChooseCust.Column(0)
If CustLookup = 0 Then
MsgBox "That customer does not exist" & Chr(13) & "Please enter a valid
customer number" & Chr(13) & "or use the search functionality provided.", ,
"F.A.C.T.S."
ICust = 0
ICust.SetFocus
Else
CustLookup = cboChooseCust.Column(0)
End If

===============================
gtfo:
Exit Sub
AwwwShit:
MsgBox Err.Description, , "F.A.C.T.S."
Resume gtfo
End Sub

What am I doing wrong? The table I want to look in is called tblCustomers,
the field I want to look for the value in is called CusNo.

Damo
 
B

Brendan Reynolds

I don't recognize that code, Damien. What was the subject line of the
original thread?

In the meantime, the most immediately obvious problem with that code is that
"SELECT CustNo(*)" is not valid SQL. I expect the original was probably
"SELECT Count(*)".

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top