jeran042
Registered User.
- Local time
- Today, 04:30
- Joined
- Jun 26, 2017
- Messages
- 127
I have a data entry form that takes numerous pieces of information. Mainly up to 5 invoice numbers (in 5 separate bound text boxes). In the after update of each text boxes I have this piece of code running:
This is currently working great, and has served a VERY valuable purpose. However, now we are approaching 55k records, this code seems to take a while to run. My question is, how can I tweek this or modify this to be more efficient, or run faster?
Please bare in mind that while I did create the database (my actual first ever Access database) that this code resides in, I am no longer in that department, so spending the time to redesign the tables schema to only take 1 invoice per record in no longer an option.
Any help or suggestions would be greatly appreciated!
Code:
Private Sub Invoice_1_AfterUpdate()
If Me.Invoice_1 <> "" Then
If Duplicate_invoice(Me.Invoice_1) = 6 Then
Me.Invoice_1 = ""
Me.Assigned_To.SetFocus
Me.Invoice_1.SetFocus
End If
End If
End Sub
Private Sub Invoice_2_AfterUpdate()
If Me.Invoice_2 <> "" Then
If Duplicate_invoice(Me.Invoice_2) = 6 Then
Me.Invoice_2 = ""
Me.Assigned_To.SetFocus
Me.Invoice_2.SetFocus
End If
End If
End Sub
Private Sub Invoice_3_AfterUpdate()
If Me.Invoice_3 <> "" Then
If Duplicate_invoice(Me.Invoice_3) = 6 Then
Me.Invoice_3 = ""
Me.Assigned_To.SetFocus
Me.Invoice_3.SetFocus
End If
End If
End Sub
Private Sub Invoice_4_AfterUpdate()
If Me.Invoice_4 <> "" Then
If Duplicate_invoice(Me.Invoice_4) = 6 Then
Me.Invoice_4 = ""
Me.Assigned_To.SetFocus
Me.Invoice_4.SetFocus
End If
End If
End Sub
Private Sub Invoice_5_AfterUpdate()
If Me.Invoice_5 <> "" Then
If Duplicate_invoice(Me.Invoice_5) = 6 Then
Me.Invoice_5 = ""
Me.Assigned_To.SetFocus
Me.Invoice_5.SetFocus
End If
End If
End Sub
Function Duplicate_invoice(invoice_f As String) As Byte
Dim VName_Inv As String
Dim VNum_Inv As String
Dim i As Byte
For i = 1 To 5
VName_Inv = Nz(DLookup("Vendor_Name", "qryINV_LOOKUP", _
"Invoice_" & i & "= '" & invoice_f & "'"), "")
VNum_Inv = Nz(DLookup("Vendor_Number", "qryINV_LOOKUP", _
"Invoice_" & i & " = '" & invoice_f & "'"), "")
If VName_Inv <> "" Then Exit For
Next
If VName_Inv <> "" Then Duplicate_invoice = MsgBox("This invoice may already exist and relates to:" & Chr(10) & _
"Vendor Name:" & Chr(9) & VName_Inv & Chr(10) & _
"Vendor Number:" & Chr(9) & VNum_Inv & Chr(10) & "Do you want to delete and enter other value?", vbYesNo + vbInformation, "Duplicate Entry!")
End Function
This is currently working great, and has served a VERY valuable purpose. However, now we are approaching 55k records, this code seems to take a while to run. My question is, how can I tweek this or modify this to be more efficient, or run faster?
Please bare in mind that while I did create the database (my actual first ever Access database) that this code resides in, I am no longer in that department, so spending the time to redesign the tables schema to only take 1 invoice per record in no longer an option.
Any help or suggestions would be greatly appreciated!