Update form with barcode in Ms Access (1 Viewer)

Alhakeem1977

Registered User.
Local time
Today, 22:19
Joined
Jun 24, 2017
Messages
308
Hi All,

How can I get the below code to update my query through a barcode scanner?
It should check the if the [ICReceived] is false then it should not update.

Thanks in acvance.

Code:
Private Sub txtBar_AfterUpdate()
  On Error Resume Next
  '''''''''''''''''''''''''''''''''''''
    If IsNull(Me!txtBar) Then
        Me.Filter = ""
    Me.FilterOn = False
 Else
     '   Me.cmdSave.Enabled = True
    Me.Filter = "[Batch ID] = '" & Me![txtBar] & "'"
        Me.FilterOn = True
    Me.Requery
Me.Refresh

   If Len(Nz(Me!ICReceived, "")) = 0 Then
        Beep

        Me.lbl1.Visible = True
        Me.lbl1.BackColor = vbRed
        Me.txtBar.SetFocus
        Me.txtBar = Null
Me![lbl1].Caption = "BATCH REJECTED" & vbNewLine & "Please acknowledge this batch first !"

        Me.txtBar.SetFocus
Else
        Me.lbl1.Visible = True
    Me.SentDate = Now
    Me.txtUserID = DLookup("UserID", "tblUser", "[UserLogin]='" & Environ("UserName") & "'")
    Me.ToPrint = True

     DoCmd.RunCommand acCmdSaveRecord
     Me![lbl1].Caption = "SAVED" & vbNewLine & "To retreat select the record then press Delete"
     Me.lbl1.BackColor = vbGreen

     Me.txtNo.Requery
     Me.List236.Requery

     Beep
    Me.txtID.Visible = True
    Me.lbl1.Visible = True
    Me.txtBar = Null
    Me.txtBar.SetFocus
    Beep


End If
End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:19
Joined
Oct 29, 2018
Messages
21,454
Hi. To update a query? Which query? Is txtBar where the barcode scanner is putting the scan?
 

Alhakeem1977

Registered User.
Local time
Today, 22:19
Joined
Jun 24, 2017
Messages
308
Hi. To update a query? Which query? Is txtBar where the barcode scanner is putting the scan?

Actually it's a select query filtered with a textbox called txtBar in the After Update event.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:19
Joined
Oct 29, 2018
Messages
21,454
Actually it's a select query filtered with a textbox called txtBar in the After Update event.
Hi. Are you saying you want to use a QueryDef object or are you using a parameter query? Can you show us the SQL statement? Thanks.
 

Alhakeem1977

Registered User.
Local time
Today, 22:19
Joined
Jun 24, 2017
Messages
308
it's here I don't know what type of queries it is!
I am sorry to bother you with me.

Code:
SELECT DeptSeq.PK, DeptSeq.DDate, [ShortName] & Format([ID],"000") & Format([DDate],"yy") AS [Batch ID], DeptSeq.CreatedID, DeptSeq.ICReceived, DeptSeq.SentDate, DeptSeq.SenderID, tblUser_1.UserLogin, tblUser_1.FirstName, DeptSeq.Received, DeptSeq.ToPrint, Department.DepartmentName
FROM Department RIGHT JOIN (tblUser AS tblUser_1 RIGHT JOIN (tblUser RIGHT JOIN DeptSeq ON tblUser.UserID = DeptSeq.CreatedID) ON tblUser_1.UserID = DeptSeq.SenderID) ON Department.DepartmentID = DeptSeq.DepartmentID
ORDER BY DeptSeq.PK;
 

Cronk

Registered User.
Local time
Tomorrow, 05:19
Joined
Jul 4, 2013
Messages
2,771
Does the code run? I think that input from a bar code reader into a text box does not trigger the After_Update event.


@dbGuy, I think the OP means updating table data on which the select query is based - there's no WHERE clause in the query.
 

Minty

AWF VIP
Local time
Today, 20:19
Joined
Jul 26, 2013
Messages
10,368
@Cronk, depends on if the BC reader is set to send an <enter> after a successful read. That's how ours are set up.

Makes for quick data entry. :)
 

Cronk

Registered User.
Local time
Tomorrow, 05:19
Joined
Jul 4, 2013
Messages
2,771
My experience with bar code readers is very limited and I recall using the Change event for input. Now that you've pointed out about the <enter>, it was probably just a case of that option being disabled. Next time .... Thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:19
Joined
Oct 29, 2018
Messages
21,454
Hi All,

How can I get the below code to update my query through a barcode scanner?
Here's the original question. What does "update my query" mean? I don't see anywhere in the code where a query is used or updated. I guess I'm just a little confused.
 

Alhakeem1977

Registered User.
Local time
Today, 22:19
Joined
Jun 24, 2017
Messages
308
Does the code run? I think that input from a bar code reader into a text box does not trigger the After_Update event.


@dbGuy, I think the OP means updating table data on which the select query is based - there's no WHERE clause in the query.
Thanks all for your earliest response.
Sorry for the delay.

Yes, the code is working normally it filtered the existing barcodes but am not getting below the filter working for sure the code is wrong.

I don't know whether I have to change the query syntax or redesign the to continuous form.

If it's possible I prefer to change the if statement in the after update field.

Thanks a lot.

Sent from my HUAWEI NXT-L29 using Tapatalk
 

Alhakeem1977

Registered User.
Local time
Today, 22:19
Joined
Jun 24, 2017
Messages
308
Here's the original question. What does "update my query" mean? I don't see anywhere in the code where a query is used or updated. I guess I'm just a little confused.
Thank you all very much I got it solved by adding a button moved it code from on click event to on set focus event it works fine now.


Sent from my HUAWEI NXT-L29 using Tapatalk
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:19
Joined
Feb 28, 2001
Messages
27,146
Actually, moving an event from one place to the other is often the right solution. Glad you found it. Part of the problem is not knowing WHERE or HOW to do something but WHEN to do it - which means that proper selection of your events becomes important.
 

Users who are viewing this thread

Top Bottom