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
 
One thing that I just did notice is that the userform does not set the focus back on the barcode textbox. There is nothing that has focus when the msgbox should be on the screen. I can click on the textbox and send another input and it works the focus is gone when the error occurs.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Right now I am only running the code my pressing play in the editor. I am not calling the code from any other location at the moment.
I don't user userforms a lot, but I am not sure if it will work that way, as I don't think it will "capture" your values from the userform since running it that way is not connecting it to your userform (especially your "me" references).

Try running it the way it is intended instead of "pressing play..." and see if that makes a difference.
 
Upvote 0
I don't user userforms a lot, but I am not sure if it will work that way, as I don't think it will "capture" your values from the userform since running it that way is not connecting it to your userform (especially your "me" references).

Try running it the way it is intended instead of "pressing play..." and see if that makes a difference.
I am only running it directly from the VB editor by either pressing F5 or hitting play from the menu.
 
Upvote 0
IF I modify my code to add two lines to change the output on the screen within the userform, I can generate a similar message but it still does not generate the msgbox.

VBA Code:
   Else
    
           Confirmation.Caption = Barcode & " could not be found."
           inv_count.Caption = "Counted " & "0" & "     Inventory " & "0"

        MsgBox "Barcode " & Barcode & " Not Found.  " & Chr(10) & "Try again", vbOKOnly
        
    End If
 

Attachments

  • Screenshot 2021-08-09 143800.jpg
    Screenshot 2021-08-09 143800.jpg
    20.4 KB · Views: 10
Upvote 0
I am only running it directly from the VB editor by either pressing F5 or hitting play from the menu.
That is what I mean! I don't think it will work that way!
If it is not being called from the User Form, I don't think the values from the User Form will be captured and it won't work!
 
Upvote 0
That is what I mean! I don't think it will work that way!
If it is not being called from the User Form, I don't think the values from the User Form will be captured and it won't work!
This part of the program is being called from the user form. Im sorry I misunderstood you. I run the userform from the VBA editor and when I scan a number into one of the text boxes it calls and runs this program.
 
Upvote 0
I don't think there is much more assistance I can offer without having access to the workbook and some dummy data to run it against.
 
Upvote 0
I'm in the same boat.
When I create a mock up of the code, my MsgBox appears every time as it should.
I've run it straight from the worksheet; I've run it from a Userform; I've run it live and I've run it F5 & F8
 
Upvote 0
I'm in the same boat.
When I create a mock up of the code, my MsgBox appears every time as it should.
I've run it straight from the worksheet; I've run it from a Userform; I've run it live and I've run it F5 & F8
I would be more than happy to share the file with anybody interested. I am not not sure how to share it on this board. I would be happy to email it to anybody if you want to take a look at it. Not sure if I can share my email address here or not so I will wait for confirmation before I do.
 
Upvote 0
I would be more than happy to share the file with anybody interested. I am not not sure how to share it on this board. I would be happy to email it to anybody if you want to take a look at it. Not sure if I can share my email address here or not so I will wait for confirmation before I do.
Put your spreadsheet in a dropbox and share the link to the box here.
 
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