message box not appearing

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
350
Office Version
  1. 365
Platform
  1. Windows
I was working on some code with some help from you guys. I have the code running now but when I search for an item if its not there I want to display a message box announcing it. When I run the code normally it skips the msgbox code(or displays it someplace not visible to the user). IF I put a stop command in, the code will execute perfectly and display the msgbox as requested. If I run it normally it skips it again.

I am totally baffled by this one.

VBA Code:
Private Sub barcode_Change()
    Dim Found           As Range
    Dim Search          As String
    Dim ws              As Worksheet
    Dim SearchColumn    As Variant
    
    Search = Me.Barcode.Value
    If Len(Search) <> 13 Then Exit Sub
    
    Set ws = ThisWorkbook.Worksheets("Physical Inventory List")
    
    SearchColumn = 5
    
    Set Found = ws.Columns(SearchColumn).Find(Search, LookIn:=xlValues, lookat:=xlWhole)
    If Not Found Is Nothing Then
        
        With Found

            .Offset(, 2).Value = Found.Offset(, 2) + Me.qty.Value
            Confirmation.Caption = Found.Offset(, -3) & " has been recorded in inventory"
            inv_count.Caption = "Counted " & Found.Offset(, 2) & "     Inventory " & Found.Offset(, 1)
        End With
        
      Else

'this is the msgbox that I want to display if the barcode is not found in the search.
        res = MsgBox("Barcode " & Search & " Not Found.  " & Chr(10) & "Try again", 48, "Not Found")
        
    End If
    
Me.Barcode.Value = ""
Me.Barcode.SetFocus
   
    
End Sub
 
when I scan a number into one of the text boxes it calls and runs this program.
It maybe that the barcode scanner has focus, hence you don't see the message box.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here is a link to the file.


I just ran your code and the message box works every time as it is supposed to for me.

I did F8 steps, and used bar code 8018851484955.
Soon as I enter this number, the message box displayed as required, including the bogus bar code.

Maybe try save and close. Then reload your spreadsheet?
 
Upvote 0
I just ran your code and the message box works every time as it is supposed to for me.

I did F8 steps, and used bar code 8018851484955.
Soon as I enter this number, the message box displayed as required, including the bogus bar code.

Maybe try save and close. Then reload your spreadsheet?
 
Upvote 0
That is strange. It still wont work on my laptop. Maybe it is something specific with my laptop. I will try it on another computer and see if it has issues or not. Thanks for all of the help
 
Upvote 0
I just emailed the file to my co-worker who will be using the program and it work on his laptop. I am not sure why it is not working on mine but honestly as long as it works on his.. LIFE is GOOD. Thanks for all of the head scratching help.
 
Upvote 0
One thing that I just did notice is that the userform does not set the focus back on the barcode textbox.
because you have the qty text box tab stop set to false there is nowhere for the focus to go that will show.
Change the last part of the code from
VBA Code:
Me.Barcode.Value = ""
Me.Barcode.SetFocus
to
VBA Code:
    Me.qty.SetFocus

    With Me.Barcode
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
and see if that is more preferable.
 
Upvote 0

Forum statistics

Threads
1,223,532
Messages
6,172,878
Members
452,486
Latest member
standw01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top