Hi Crystal,
Thank you so much for all the help. As luck would have it, I am not able to
get this to work, but also, not getting any error messages. I know have the
following (this is just a snipet)
above i have all the original variable and connection openings, should these
stay the same??
~~~~~~~~~~~~~~~~~
Dim mItem_Type_ID As Long
mItem_Type_ID = Nz(DLookup("Item_Type_ID", "Items", "Item_ID=" & [Item_ID]),
0)
If Type1.Value = 1 Then
If mItem_Type_ID = 8 Or mItem_Type_ID = 9 Then
If Step.Value = "Receiving" Then
If IsNull(rst!Receiving) Then 'check Recieving isNull?
rst!Receiving = Now()
rst![Received By] = Employee
rst.Update
MsgBox "Update Successful"
Else
DoCmd.Beep
MsgBox "Error", vbInformation, "ERROR"
MsgBox "Item has already been Received - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
ElseIf Step.Value = "Scanning" Then...
Sorry, what have I done wrong?
thanks!
-gary
:
Hi Gary,
dLookup is slow -- so you should only do it once and assign its return
to a variable
this statement, for instance, has 2 of them:
If DLookup("Item_Type_ID", "Items", "Item_ID=" & [Item_ID]) = 8 Or
DLookup("Item_Type_ID", "Items", "Item_ID=" & [Item_ID]) = 9
instead, consider this:
'~~~~~~~~~~~~~~~
dim mItem_Type_ID as Long
mItem_Type_ID = nz(DLookup("Item_Type_ID", "Items", "Item_ID=" &
[Item_ID]),0)
'statements
if mItem_Type_ID = 8 or mItem_Type_ID = 9 then
'statements
'~~~~~~~~~~~~~~~
I wrapped the result in nz (null-to-zero) in case dLookup didn't find
anything -- otherwise, you will have an error if it doesn't.
~~~
"update the table with a date and employee for a specific
production step "
it looks as though your data is not properly structured. Rather than
having fields for each step ... consider this:
*StepTypes*
StepTypeID, autonumber
Step, text -- receiving, scanning, etc
*ProductionSteps*
StepID, autonumber
someID, long integer -- foreign key to relate to the main record
StepTypeID, long integer -- FK to StepTypes
StepDate, date/time
StepUser, text
By doing this, you will save yourself a LOT of effort when it comes to
reporting and tracking too. More time spent in setting up a good
structures saves countless headaches and problems down the road...
to help you understand how to structure data in Access, send me an email
and request my 30-page Word document on Access Basics (for Programming)
-- it doesn't cover VBA, but prepares you for it because it covers
essentials in Access. Be sure to put "Access Basics" in the subject
line so that I see your message...
Warm Regards,
Crystal
*
have an awesome day
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
Gary Dolliver wrote:
Hi Crystal!
I tried using a combo box instead of a regular text box, but it seemed to
take the same amount of time to update, which was discouraging... I am
wanting to update the table with a date and employee for a specific
production step that an item is going through, which to my knowledge is not a
calculated field, just a date and name.
What I am beginning to think is that I have too much code to verify too many
things about the item being scanned... I am including part of my current
code below.
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set con = CurrentProject.Connection 'Control Name -
[Forms]![RECEIVING_PRODUCTION_Step_Check_In]![Item_ID]
Set rst = New ADODB.Recordset
rst.Open "Items", con, adOpenKeyset, adLockOptimistic 'open the table Items
If IsNull([Forms]![RECEIVING_PRODUCTION_Step_Check_In]![Item_ID]) Then 'in
case Item_ID field is null
MsgBox "No Item ID to Update", vbCritical, "ERROR"
Exit Sub
Else ' if Item_ID is not null
rst.Find "Item_ID = " &
Forms![RECEIVING_PRODUCTION_Step_Check_In]![Item_ID], , adSearchForward
End If
Debug.Print rst!Item_ID 'check Item_ID - to delete “Debug.Print†after use
If Type1.Value = 1 Then
'need to double check item_type_id to make sure correct info is passed across
If DLookup("Item_Type_ID", "Items", "Item_ID=" & [Item_ID]) = 8 Or
DLookup("Item_Type_ID", "Items", "Item_ID=" & [Item_ID]) = 9 Then
If Step.Value = "Receiving" Then
If IsNull(rst!Receiving) Then 'check Recieving isNull?
rst!Receiving = Now()
rst![Received By] = CurrentUser
rst.Update
MsgBox "Update Successful"
Else
DoCmd.Beep
MsgBox "Item has already been Received - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
ElseIf Step.Value = "Scanning" Then
If IsNull(rst!Scanning) Then
rst!Scanning = Now()
rst![Scanned By] = CurrentUser
rst.Update
MsgBox "Update Successful"
Else
DoCmd.Beep
MsgBox "Item has already been Scanned - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
ElseIf Step.Value = "Printing" Then
If IsNull(rst!Printing) Then
rst!Printing = Now()
rst![Printed By] = CurrentUser
rst.Update
MsgBox "Update Successful"
Else
DoCmd.Beep
MsgBox "Item has already been Printed - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
ElseIf Step.Value = "Assembly" Then
If IsNull(rst!Assembly) Then
rst!Assembly = Now()
rst![Assembled By] = CurrentUser
rst.Update
MsgBox "Update Successful"
Else
DoCmd.Beep
MsgBox "Item has already been Assembled - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
ElseIf Step.Value = "Trimming" Then
If IsNull(rst!Trimming) Then
rst!Trimming = Now()
rst![Trimmed By] = CurrentUser
rst.Update
MsgBox "Update Successful"
Else
DoCmd.Beep
MsgBox "Item has already been Trimmed - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
ElseIf Step.Value = "Shipping" Then
If IsNull(rst!Shipping) Then
rst!Shipping = Now()
rst![Shipped By] = CurrentUser
rst.Update
MsgBox "Update Successful"
DoCmd.RunSQL "INSERT INTO Ship_Order (Item_ID, Shipper,
Ship_Scan_Date) VALUES (Item_ID, CurrentUser, Now())"
Else
DoCmd.Beep
MsgBox "Item has already been Shipped - Please hold for
Management", vbInformation, "ERROR"
End If
Set rst = Nothing
End If
Else
MsgBox ("Error - Incorrect Item Type Being Scanned")
End If
Now it will begin an If for Type2.... and then Type3... and so on...
Any way to stream line this?? ha!
thanks!
-gary
:
Hi Gary,
How about simply making the ItemNumber a combobox with other columns for
the info you want to echo?
in another control, you can display info from other columns like this:
=combobox_controlname.column(1)
where this is really the second column since indexing starts with 0
you can also, of course, grab this value in code too:
Me.combobox_controlname.column(1)
why are you wanting to update another table? You are not storing
calculated fields, are you?
Warm Regards,
Crystal
*
have an awesome day
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
Gary Dolliver wrote:
Hi all,
I have a form that has an entry field where I will be using a barcode
scanner to enter an item number. Once the number is inserted into the field,
I would like to update certain records within the items table, bases on the
item number inserted. What would be the fastest search method to use to look
up the item number and make the update? DLookup? FindRecord? If someone
could provide any examples, I would be very appreciative, thanks!
-gary