Kryst51
Singin' in the Hou. Rain
- Local time
- Yesterday, 20:56
- Joined
- Jun 29, 2009
- Messages
- 1,896
Hi Folks,
I haven't been on very much recently due to being moved to a new position at work, I hope ya'll are well.
To the point.
I have a form where in the before update event I have the following code (ByPass is declared public to the form at the top of the vba window as an Integer):
The form updates when a save button is clicked. My goal is that it will check to see if this invoice has already been entered then give the user two options, one - go to that invoice to see if it's the one they are entering, two- cancel the save, to check and make sure they didn't mistype their invoice number.
Here is the code behind my save button:
The red portion is the portion that I am trying to get to work. I get the "No Current record error just after the vba has gone through the before update event and is moved back to the save button code. The error is on line 170.
I have done some reading and the only solution I found is to use the error handler to ignore the error, if I do that and move to the next line of code I get a different error on line 230 that is number 2105 "You can't go to the specified record".
Any help with either error would be appreciated.
I haven't been on very much recently due to being moved to a new position at work, I hope ya'll are well.
To the point.
I have a form where in the before update event I have the following code (ByPass is declared public to the form at the top of the vba window as an Integer):
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim msgResponse As VbMsgBoxResult
10 On Error GoTo Form_BeforeUpdate_Error
20 If Me.NewRecord = False Then
30 Resume Next
40 Else
50 If Len(DLookup("InvoiceNumber", _
"tblInvoices", "InvoiceNumber =" & Chr(34) & _
Me.InvoiceNumber & Chr(34))) > 0 Then
60 msgResponse = MsgBox( _
"This Invoice has already been entered." & vbCrLf _
& _
"Click 'OK' to go to the invoice (Check if you are duplicating)" _
& vbCrLf & _
"Click 'Cancel' to return to this record to change the invoice number if you mistyped it.", _
vbOKCancel)
70 Select Case msgResponse
Case 1
80 ByPass = 2
90 Cancel = True
110 Case 2
120 ByPass = 1
130 Cancel = True
140 End Select
150 Else
160 Cancel = True
170 End If
180 End If
Form_BeforeUpdate_Exit:
190 Exit Sub
Form_BeforeUpdate_Error:
200 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_BeforeUpdate of VBA Document Form_frmEnterInvoice on line " & Erl
210 GoTo Form_BeforeUpdate_Exit
End Sub
The form updates when a save button is clicked. My goal is that it will check to see if this invoice has already been entered then give the user two options, one - go to that invoice to see if it's the one they are entering, two- cancel the save, to check and make sure they didn't mistype their invoice number.
Here is the code behind my save button:
Code:
Private Sub btnSaveInvoice_Click()
10 On Error GoTo btnSaveInvoice_Click_Error
Dim ctl As Control
Dim cnt As Integer
Dim IntgotoRecord As Integer
20 If Me.Dirty = False Then GoTo btnSaveInvoice_Click_Exit
30 cnt = 0
40 For Each ctl In Me.Controls
50 If ctl.Tag = "Highlight" Then
60 If Not Len(Nz(ctl.Value, "")) > 0 Then
70
80 ctl.BackColor = fRed()
90 ctl.ForeColor = fWhite()
100 cnt = cnt + 1
110 End If
120 End If
130 Next ctl
140 If cnt > 0 Then
150 MsgBox _
"The Highlighted fields must be filled in"
160 Else
[COLOR=red][B]170 If Me.Dirty = True Then DoCmd.RunCommand acCmdSaveRecord[/B][/COLOR]
[COLOR=red][B]180 If ByPass = 1 Then
190 GoTo btnSaveInvoice_Click_Exit
200 ElseIf ByPass = 2 Then
210 IntgotoRecord = _
DLookup("pkInvoiceID", "tblInvoices", _
"InvoiceNumber =" & Chr(34) & Me.InvoiceNumber & _
Chr(34))
220 Me.Undo
230 DoCmd.gotoRecord , , , _
IntgotoRecord
[/B][/COLOR]240 Call ResetEditControls
250 End If
260 ByPass = 0
270 End If
btnSaveInvoice_Click_Exit:
280 Exit Sub
btnSaveInvoice_Click_Error:
290 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure btnSaveInvoice_Click of VBA Document Form_frmEnterInvoice on line " & Erl
300 GoTo btnSaveInvoice_Click_Exit
End Sub
The red portion is the portion that I am trying to get to work. I get the "No Current record error just after the vba has gone through the before update event and is moved back to the save button code. The error is on line 170.
I have done some reading and the only solution I found is to use the error handler to ignore the error, if I do that and move to the next line of code I get a different error on line 230 that is number 2105 "You can't go to the specified record".
Any help with either error would be appreciated.