you add code to the KeyDown event of your Form.
but before that make sure to Set the Key Preview property of the Form to Yes.
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF8 Then
'goto previous record
DoCmd.GoToRecord , , acPrevious
ElseIf KeyCode = vbKeyF9 Then
'goto next record
DoCmd.GoToRecord , , acNext
End If
End Sub
you add code to the KeyDown event of your Form.
but before that make sure to Set the Key Preview property of the Form to Yes.
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF8 Then
'goto previous record
DoCmd.GoToRecord , , acPrevious
ElseIf KeyCode = vbKeyF9 Then
'goto next record
DoCmd.GoToRecord , , acNext
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 113 Then Text1.SetFocus
If KeyCode = 114 Then List4.SetFocus
If KeyCode = 115 Then
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
sql = "delete from jualdetail where nofaktur_jual='" & Label2.Caption & "' and barcode = '" & List4.Column(0) & "'"
cn.Execute (sql)
tampil
total_jual
End If
If KeyCode = 116 Then Text26.SetFocus
just replace your keydown code with this one (already cleaned)
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case Is = 113
Text1.SetFocus
Case Is = 114
List4.SetFocus
Case Is = 115
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
SQL = "delete from jualdetail where nofaktur_jual='" & Label2.Caption & "' and barcode = '" & List4.Column(0) & "'"
cn.Execute (SQL)
tampil
total_jual
Case Is = 116
Text26.SetFocus
Case Is = vbKeyF8
'goto previous record
DoCmd.GoToRecord , , acPrevious
Case Is = vbKeyF9
'goto next record
DoCmd.GoToRecord , , acNext
End Select
End Sub
just replace your keydown code with this one (already cleaned)
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case Is = 113
Text1.SetFocus
Case Is = 114
List4.SetFocus
Case Is = 115
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
SQL = "delete from jualdetail where nofaktur_jual='" & Label2.Caption & "' and barcode = '" & List4.Column(0) & "'"
cn.Execute (SQL)
tampil
total_jual
Case Is = 116
Text26.SetFocus
Case Is = vbKeyF8
'goto previous record
DoCmd.GoToRecord , , acPrevious
Case Is = vbKeyF9
'goto next record
DoCmd.GoToRecord , , acNext
End Select
End Sub
Hi All, I've made a bare basic Access db. I have also added some records navigation buttons for it. The thing is, when if I am on the very first record or the last record, and I press previous or next buttons, I get the Run Time Error 2105. 16787 Is there a code that I could use so...
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Goto Err_Handler
Select Case KeyCode
Case Is = 113
Text1.SetFocus
Case Is = 114
List4.SetFocus
Case Is = 115
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
SQL = "delete from jualdetail where nofaktur_jual='" & Label2.Caption & "' and barcode = '" & List4.Column(0) & "'"
cn.Execute (SQL)
tampil
total_jual
Case Is = 116
Text26.SetFocus
Case Is = vbKeyF8
'goto previous record
DoCmd.GoToRecord , , acPrevious
Case Is = vbKeyF9
'goto next record
DoCmd.GoToRecord , , acNext
End Select
Exit_Sub:
Exit Sub
Err_Handler:
If Err <> 2105 Then
MsgBox Err.Number & ": " & Err.Description
End If
Resume Exit_Sub
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Goto Err_Handler
Select Case KeyCode
Case Is = 113
Text1.SetFocus
Case Is = 114
List4.SetFocus
Case Is = 115
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
SQL = "delete from jualdetail where nofaktur_jual='" & Label2.Caption & "' and barcode = '" & List4.Column(0) & "'"
cn.Execute (SQL)
tampil
total_jual
Case Is = 116
Text26.SetFocus
Case Is = vbKeyF8
'goto previous record
DoCmd.GoToRecord , , acPrevious
Case Is = vbKeyF9
'goto next record
DoCmd.GoToRecord , , acNext
End Select
Exit_Sub:
Exit Sub
Err_Handler:
If Err <> 2105 Then
MsgBox Err.Number & ": " & Err.Description
End If
Resume Exit_Sub
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Goto Err_Handler
Select Case KeyCode
Case Is = 113
Text1.SetFocus
Case Is = 114
List4.SetFocus
Case Is = 115
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
SQL = "delete from jualdetail where nofaktur_jual='" & Label2.Caption & "' and barcode = '" & List4.Column(0) & "'"
cn.Execute (SQL)
tampil
total_jual
Case Is = 116
Text26.SetFocus
Case Is = vbKeyF8
'goto previous record
DoCmd.GoToRecord , , acPrevious
Case Is = vbKeyF9
'goto next record
DoCmd.GoToRecord , , acNext
End Select
Exit_Sub:
Exit Sub
Err_Handler:
If Err <> 2105 Then
MsgBox Err.Number & ": " & Err.Description
End If
Resume Exit_Sub
End Sub
Thank you sir for all the explanations, I salute your patience in guiding me, there is one more thing I want to ask, I hope you are pleased to answer it.
I have a combobox (combo6) it contains data on the name of the item, and I also have a text box (text1) that contains the code for the item, when I type only 1 letter of data from the item name in combo6, combo6 immediately appears item data according to the letter the first thing I typed, it's just that the text1 doesn't immediately appear the code from the item. the item code can only appear if I use my mouse then I click the arrow then look for the item data then I click then the item code appears in text1. this way makes me slow
my wish is that as soon as I type the name of the item in the combobox, the item name appears immediately (and this is exactly what I wanted), and the text1 also appears according to the code of the item and once everything is in order both in combo6 and text1 then when I press enter the data goes directly to the list.
can you help
text1 already has coding as below, only I added a combobox to make it easier to find item names
this is coding text1
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
c_barcode = Text1
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
sql = "Select * from jual where nofaktur_jual='" & Text2 & "'"
rs.Open sql, cn, adOpenKeyset
If rs.EOF Then
sql = "insert into jual (nofaktur_jual,tgl_jual,idkasir)values (" & _
"'" & Text2 & "','" & Date & "','" & id_kasir & "')"
cn.Execute (sql)
End If
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
Set cn = CurrentProject.AccessConnection
If Left(Text1.Text, 1) = "#" Then
sql = "update jualdetail set qty_jual='" & Split(Text1.Text, "#")(1) & "' where nofaktur_jual='" & Text2 & "' and barcode='" & c + Barcode & "'"
cn.Execute (sql)
Else
sql = "Select * from jualdetail where nofaktur_jual='" & Text2 & "' and barcode='" & Text1.Text & "'"
rs.Open sql, cn, adOpenKeyset
If rs.EOF Then
sql = " insert into jualdetail (nofaktur_jual,barcode,qty_jual)values (" & _
"'" & Text2 & "','" & Text1.Text & "',1)"
cn.Execute (sql)
Else
sql = "update jualdetail set qty_jual=qty_jual+1 where nofaktur_jual='" & Text2 & "' and barcode='" & Text1.Text & "'"
cn.Execute (sql)
End If
End If
tampil
total_jual
c_barcode = Text1.Text
Text1 = ""
Text1.SetFocus
End If
End Sub
I cannot help with your query, but do yourself a favour early on. Give your controls some meaningful names. If you come back 3 months later to make amendments, Text1 is not going to mean a thing to you or anyone else that might have to work with the code.
Your code is virtual gibberish. It is not properly formatted and the names are meaningless. And running update queries in the KeyDown event of a control makes absolutely no sense. Why would you not use the click event of a button?
Do NOT use ENTER to advance to the next record. Return the Access default to what it was.
Then you can show the navigation bar on your form OR you can create your own buttons if you like to write unnecessary code. You can still automatically advance if you want to but that also makes no sense. How do you know the user has a payment for the next invoice? The user should have a search box or a combo that lets him select the invoice that way.