This is my code for one of my commands. My Problem is that all of this even on a fast connection to a pretty fast server can take as long as 7 seconds to process and either open the form or not depending on whether my conditions were met. Is there a faster way for me to do this?
Code:
Private Sub Command3_Click()
varx = DLookup("[St1_Status]", "Serial_Number_Log", "[Serial_Number] = Text5")
varx2 = DLookup("[St2_Status]", "Serial_Number_Log", "[Serial_Number] = Text5")
varx3 = DLookup("[St3_Status]", "Serial_Number_Log", "[Serial_Number] = Text5")
varx4 = DLookup("[St4_Status]", "Serial_Number_Log", "[Serial_Number] = Text5")
varx5 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 1' and [Defect Fixed?]=false")
varx6 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 2' and [Defect Fixed?]=false")
varx7 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 3' and [Defect Fixed?]=false")
varx8 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 4' and [Defect Fixed?]=false")
var5 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 1'")
var6 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 2'")
var7 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 3'")
var8 = DLookup("[Defect Fixed?]", "Defect_Log", "[Serial_Number]= text5 And [Station] like 'Station 4'")
Closed = DLookup("[Closed]", "Serial_Number_Log", "[Serial_Number] = Text5")
If (Text5.Value = "" Or Text5.Value = Null Or Text5.Value = 0 Or Closed = True) Then
MsgBox ("Please Enter a Valid Serial Number!")
Else
If (varx = "NA" And varx2 = "NA" And varx3 = "NA" And varx4 = "NA") Then
DoCmd.OpenForm "Radio Test Data Entry", acNormal, "", "[Forms]![Enter Serial]![Text5]=[Serial_Number_Log]![Serial_Number] And [Serial_Number_Log]![St1_Status]=""NA"" And [Serial_Number_Log]![St2_Status]=""NA"" And [Serial_Number_Log]![St3_Status]=""NA"" And [Serial_Number_Log]![St4_Status]=""NA""", acEdit, acNormal
ElseIf (varx = "Pass" And varx2 = "Pass" And varx3 = "Pass" And varx4 = "Pass") Then
DoCmd.OpenForm "Radio Test Data Entry", acNormal, "", "[Forms]![Enter Serial]![Text5]=[Serial_Number_Log]![Serial_Number] And [Serial_Number_Log]![St1_Status]=""Pass"" And [Serial_Number_Log]![St2_Status]=""Pass"" And [Serial_Number_Log]![St3_Status]=""Pass"" And [Serial_Number_Log]![St4_Status]=""Pass""", acEdit, acNormal
'Test if the serial number status for a particular station is Pass or Fail and whether the defect has been fixed
'if the status is fail and defect hasn't been fixed don't let the user thru
'if the defect has been fixed let the user thru.
ElseIf ((varx = "Fail" And varx5 = False) Or (varx2 = "Fail" And varx6 = False) Or (varx3 = "Fail" And varx7 = False) Or (varx4 = "Fail" And varx8 = False)) Then
MsgBox ("This serial number needs rework on one of it's stations!")
ElseIf ((varx = "Fail" And var5 = True) Or (varx2 = "Fail" And var6 = True) Or (varx3 = "Fail" And var7 = True) Or (varx4 = "Fail" And var8 = True)) Then
DoCmd.OpenForm "Radio Test Data Entry", acNormal, "", "[Forms]![Enter Serial]![Text5]=[Serial_Number_Log]![Serial_Number]", acEdit, acNormal
End If
End If
End Sub