message box not appearing

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
349
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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Not sure what the , 48, is for, but it is causing the code to throw an error.

VBA Code:
MsgBox "Barcode " & Search & " Not Found.  " & Chr(10) & "Try again", vbOKOnly
 
Upvote 0
Not sure what the , 48, is for, but it is causing the code to throw an error.

VBA Code:
MsgBox "Barcode " & Search & " Not Found.  " & Chr(10) & "Try again", vbOKOnly
I am not sure if this is what is causing your issue, but you should NEVER use reserved words (words of existing functions, methods, properties, etc) as the names of your variables! "Search" is a reserved word. Try something else instead.
 
Upvote 0
Tried all of these suggestions and still the same thing.
 
Upvote 0
Try placing a line break at this line of the code:
VBA Code:
    Search = Me.Barcode.Value
Then, when your code is triggered, it should stop there, and you can progress through your code one line at a time using the F8 key.
That way you can see exactly which steps of the code it goes through, and you can hover any variable that you have passed to see that the current value is.

Often times, the issue will become readily apparent when you do that.
 
Upvote 0
Try placing a line break at this line of the code:
VBA Code:
    Search = Me.Barcode.Value
Then, when your code is triggered, it should stop there, and you can progress through your code one line at a time using the F8 key.
That way you can see exactly which steps of the code it goes through, and you can hover any variable that you have passed to see that the current value is.

Often times, the issue will become readily apparent when you do that.
Joe4,

I have done that. When I use F8 key to step through the program it works and the msg box appears. When I let it run it without the stop it does not appear. Hence my frustration
 
Upvote 0
Are you on the "Physical Inventory List" sheet when the code is run?
 
Upvote 0
Are you on the "Physical Inventory List" sheet when the code is run?
yes. The userform pops up on top of the excel sheet and I can see the code updating things in the background. But whenever that msgbox is called the code just runs right past it unless I put a line stop in and step through it.
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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