invalid value in.
The setup:
3 macros - get_clock_num, verify_clocknum, append_to_history
3 functions. each in their own module - get_clocks(), verify_clocks(),
append()
Each macro runs a function from in its corresponding module.
Here is my code.
From the "gatheremp_num" module... ________________________________________
Public Loader, Packer As String
Function get_clocks()
Packer = ""
Loader = ""
Packer = InputBox("Input packer")
Loader = InputBox("Input loader")
DoCmd.RunMacro "verify_clocknum"
End Function
_______________________________________
From the "verify" module... _______________________________________
'Verify if the Loader and Packer are clocked in using the
"look_up_empid" query
Function verify_clocks()
Dim packname, loadname As String
Dim packcount, loadcount As String
Dim lookup_emp_id As QueryDef
MsgBox "Step0"
'count the number of times each employee shows up. If null, ask for
names again
packcount = DCount("[clocknum]", "look_up_empid", "[clocknum]= '" &
Packer & "'")
loadcount = DCount("[clocknum]", "look_up_empid", "[clocknum]= '" &
Loader & "'")
If packcount = 0 Then
MsgBox "step1"
MsgBox "One or more employees not clocked in. Rescan badges"
DoCmd.RunMacro "get_clock_num"
Else
MsgBox "Step2"
GoTo Verify_Loader
End If
Verify_Loader:
MsgBox "step3"
If loadcount = 1 Then
MsgBox "step4"
GoTo Display_Results
Else
MsgBox "Step5"
MsgBox "One or more employees not clocked in. Rescan badges"
DoCmd.RunMacro "get_clock_num"
End If
Display_Results:
'Lookup employee names from loader and packer input boxes
packname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Packer & "'")
loadname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Loader & "'")
'display employee names
MsgBox ("Packer is " & packname & " " & Packer & Chr(13) & "Loader is "
& loadname & " " & Loader)
DoCmd.RunMacro "append_to_history"
End Function
_________________________________________
From the "append_history" module...
____________________________________________
Function append()
Dim SQLstr, SQLstr2, packname, loadname, order, machno As String
Dim curdate As Date
Dim look_up_empid, getorder As QueryDef
Dim history, outputtable As TableDef
' gets variables from queries
packname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Packer & "'")
loadname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Loader & "'")
order = DFirst("[ordno]", "getorder")
machno = DFirst("[mach num]", "getorder")
'declares append query to put values into history table
SQLstr = "INSERT INTO history (clockno,empname,ordno,curdate,machno)
VALUES" & _
"('" & Packer & "','" & packname & "','" & order & "',#" &
Now() & "#,'" & machno & "')"
SQLstr2 = "INSERT INTO history (clockno, empname,ordno,curdate,machno)
VALUES" & _
"('" & Loader & "','" & loadname & "','" & order & "',#" &
Now() & "#,'" & machno & "')"
'executes queries
MsgBox "step6"
DoCmd.RunSQL SQLstr
MsgBox "step7"
DoCmd.RunSQL SQLstr2
End Function
_________________________________________
I know this is alot of code and I apologize for that but I'm really
stuck and it makes no sense to me.
This code runs perfectly if I put valid 2 numbers into Packer and
Loader. Here is the steps that run when 2 good numbers are entered.
Step 0,2,3,4,6,7
Here is what happens if I put a bad number and good number.
Step 0,1
It asks again so I put in 2 good numbers
Step 0,2,3,4,6,7,3,4,6,7
Why the loop? Its displaying the good numbers twice and also appends
them into the table twice.