Code:
Private Sub txtJob_KeyUp(KeyCode As Integer, Shift As Integer)
'<EhHeader>
On Error GoTo txtJob_KeyUp_Err
'</EhHeader>
Dim DBB As Database
Dim CusRST As Recordset
Dim GenRS As Recordset
'Clears Job Number textbox and all data text boxes if 'F2' Key is pressed then exits
If KeyCode = vbKeyF2 Then
Dim oCTL As Control
Dim oTXT As TextBox
For Each oCTL In Me.Controls
If TypeOf oCTL Is TextBox Then
Set oTXT = oCTL
oTXT.Text = ""
End If
Next
Set oTXT = Nothing
Exit Sub
End If
'If 'Enter' key is pressed and a valid job number is
'entered this retrieves all job related data
If KeyCode = 13 Then
Set DBB = OpenDatabase(App.Path & "\custdb.mdb")
If Len(txtJob.Text) = 7 Then
Let CurJobNumber = txtJob.Text
Set CusRST = DBB.OpenRecordset("Customers")
Set GenRS = DBB.OpenRecordset("Generators")
If GenRS.RecordCount <= 0 Then
CusRST.Close
GenRS.Close
DBB.Close
Set CusRST = Nothing
Set GenRS = Nothing
Exit Sub
End If
With GenRS 'Generator Recordset
.Index = "genjobnum"
.Seek "=", Trim$(txtJob.Text)
If GenRS.NoMatch Then
MsgBox "The job number you entered is not valid. Please re-check you job number and try agian.", vbInformation, "Job Invalid"
txtJob.Text = ""
txtJob.SetFocus
Exit Sub
End If
With CusRST 'Customer Recordset
.Index = "CustomerID"
.Seek "=", GenRS.Fields("CustomerID").Value
'126 fraMain.Caption = txtJob.Text & ": " & cusrst.Fields("Companyname").Value
CustInfo(0).Text = CusRST.Fields("Companyname").Value 'Customer Name
CustInfo(1).Text = CusRST.Fields("address").Value 'Project ID
CustInfo(2).Text = CusRST.Fields("city").Value '& ", " & GenRS.Fields("GenFName").Value ' & vbCrLf & GenRS.Fields("Genaddress").Value & vbCrLf & GenRS.Fields("gencity").Value & ", " & GenRS.Fields("genstate").Value
CustInfo(3).Text = CusRST.Fields("state").Value
CustInfo(4).Text = Format$(CusRST.Fields("phone").Value, "(###)###-####")
CustInfo(5).Text = Format$(CusRST.Fields("fax").Value, "(###)###-####")
CustInfo(6).Text = CusRST.Fields("accountnum").Value
If CusRST.Fields("accttype").Value = "ACTIVE" Then
AcctType(0).Value = True
Else
AcctType(1).Value = True
End If
GenInfo(0).Text = IIf(IsNull(GenRS.Fields("GenFName").Value), GenRS.Fields("GenlName").Value, GenRS.Fields("GenlName").Value & ", " & GenRS.Fields("GenFName").Value)
GenInfo(1).Text = GenRS.Fields("genaddress").Value 'Project ID
GenInfo(2).Text = GenRS.Fields("gencity").Value '& ", " & GenRS.Fields("GenFName").Value ' & vbCrLf & GenRS.Fields("Genaddress").Value & vbCrLf & GenRS.Fields("gencity").Value & ", " & GenRS.Fields("genstate").Value
GenInfo(3).Text = GenRS.Fields("Genstate").Value
GenInfo(4).Text = GenRS.Fields("gencounty").Value
GenInfo(5).Text = GenRS.Fields("municipaltownship").Value
GenInfo(6).Text = Format$(GenRS.Fields("esttonnage").Value, "###,###.#0")
GenInfo(7).Text = Format$(GenRS.Fields("tonsapp").Value, "###,###.#0")
GenInfo(8).Text = Format$(GenRS.Fields("ytdtotal").Value, "###,###.#0")
GenInfo(9).Text = Format$(GenRS.Fields("tphresult").Value, "###,###")
GenInfo(10).Text = Format$(GenRS.Fields("tphlast").Value, "###,###")
GenInfo(11).Text = IIf(IsNull(GenRS.Fields("tphsub").Value), "None", GenRS.Fields("tphsub").Value)
GenInfo(12).Text = IIf(IsNull(GenRS.Fields("wcsub").Value), "None", GenRS.Fields("wcsub").Value)
GenInfo(13).Text = IIf(IsNull(GenRS.Fields("wasteclass").Value), "None", GenRS.Fields("wasteclass").Value)
GenInfo(14).Text = IIf(IsNull(GenRS.Fields("wasteclassrcvddate").Value), "N/A", GenRS.Fields("wasteclassrcvddate").Value)
GenInfo(15).Text = IIf(IsNull(GenRS.Fields("waiver").Value), "None", GenRS.Fields("waiver").Value)
GenInfo(16).Text = IIf(IsNull(GenRS.Fields("sampledate").Value), "None", GenRS.Fields("sampledate").Value)
GenInfo(17).Text = IIf(IsNull(GenRS.Fields("expiredate").Value), "None", GenRS.Fields("expiredate").Value)
End With
End With
GenRS.Close
CusRST.Close
DBB.Close
Set DBB = Nothing
End If
End If
'<EhFooter>
Exit Sub
txtJob_KeyUp_Err:
MsgBox Err.Description & vbCrLf & "in SoilExpress.Form2.txtJob_KeyUp " & "at line " & Erl
'</EhFooter>
End Sub