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

Form_Keypress

Status
Not open for further replies.

Vcscwi

Programmer
Jan 15, 2004
57
US
Hi All,

Just wondering if anyone can see anything wrong with my code... trying to get prior entered data to fill the form when press F7 or F8. If I press Escape it runs the Form_keypress, but F7 and F8 doesn't.

I do have the form keypreview set to True.

Thanks!

Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyEscape
Unload Me

Case vbKeyF7
' copy last entered invoice to form
With rsTempInvoice
.Open "SELECT * FROM tblTempInvoice ORDER BY InvoiceNumber", cnREVS, adOpenStatic, adLockReadOnly
If .RecordCount > 0 Then
.MoveLast
txtInvoiceNumber.Text = !InvoiceNumber + 1
txtLineItemNumber.Text = 1
txtDistrictID.Text = !DistrictID
txtInvoiceDate.Text = !InvoiceDate
txtEventDate.Text = !EventDate
txtGroupNum.Text = !GroupNum
txtAmount.Text = !Amount
txtPONumber.Text = !PONumber
txtDescription.Text = !Description


End If
.Close
End With


Case vbKeyF8 'copy last entered invoice except district, line, & invoice

With rsTempInvoice
.Open "SELECT * FROM tblTempInvoice ORDER BY InvoiceNumber", cnREVS, adOpenStatic, adLockReadOnly
If .RecordCount > 0 Then
.MoveLast
txtInvoiceNumber.Text = ""
txtLineItemNumber.Text = ""
txtDistrictID.Text = ""
txtInvoiceDate.Text = !InvoiceDate
txtEventDate.Text = !EventDate
txtGroupNum.Text = !GroupNum
txtAmount.Text = !Amount
txtPONumber.Text = !PONumber

End If
.Close
End With
End Select
End Sub
 
You can't use the key press event to capture function keys. You can, however, use the KeyUp event. Make sure the form's KeyPreview property is set to TRUE.

Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    
    MsgBox (KeyCode & ":" & Shift)
    
End Sub

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top