Disable MsgBox message

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,271
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I have a userform where if i leave a ComboBox empty i see a MsgBox warning me that i must enter an invoice number.

It is this MsgBox i wish to remove so in future the user is able to leave it empty if they wish BUT should they enter an invoice number the code still must check if its beeing duplicated.

Please can you advise what i need to delete so i am able to leave the field empty but still check if the value entered is duplicated then advise me.

This is part of the code we need to edit.

VBA Code:
Private Sub CommandButton1_Click()
    With Sheets("DATABASE")
        If Len(Me.ComboBox13.Text) = 0 Then
            With Me.ComboBox13
                 MsgBox "You Must Enter An Invoice Number", vbCritical, "INVOICE NUMBER FIELD EMPTY MESSAGE"
                .Value = "": .SetFocus
            End With
            Exit Sub
        ElseIf Application.CountIf(.Columns(16), Me.ComboBox13.Text) > 0 And Not Me.ComboBox13.Text = "N/A" Then
            With Me.ComboBox13
                MsgBox "Invoice Number " & .Text & " Already Exists", vbCritical, "DUPLICATE INVOICE NUMBER MESSAGE"
                .Value = "": .SetFocus
            End With
            Exit Sub

        ElseIf IsNumeric(Me.ComboBox13.Text) Or Me.ComboBox13.Text = "N/A" Then
 
The reason why I asked is it correct what I supplied Is because now nothing is transfered from userform to worksheet.
Ok I don’t see the error message but nothing is transferred from userform to worksheet.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Put a break points into your code at With Sheets("DATABASE") and step through.

The decision logic is failing somewhere. You are exiting the subroutine before you get to transferring the data into the spreadsheet.
 
Last edited:
Upvote 0
Stepping through i see the userform but it loops through but then doesnt exit and i just keep going around and around
 
Upvote 0
Which bit is it looping through?

When you are stepping through, monitor all your variables and values. That will give you an indication of where it is falling over. At each decision step, look at the variables and the logic.

Things to look out for are values which appear blank, but contain a white space. Values where the result of a calculation or comparison is not what you expect, e.g. there is an "=" instead of "<>". Those kinds of things. I guarantee that when you spot it, you will facepalm yourself.

I have looked through the logic and nothing is jumping out at me. Maybe a fresh pair of eyes would spot it straight away.

As an aside. It helps in debugging, particularly when asking others for help, if you give the userform components relevant names. For example, instead of combox13 rename it to be InvoiceNumber, CommandButton1 rename as OKButton. etc.
 
Upvote 0
No problems.

I've had coding problems which had me stumped all day or more. Then on the way home whilst deafening myself with some Led Zeppelin, the answer hit me like a flash.

What often works for me and might help you, is to get someone with some coding experience to sit next to you, while you explain your problem and explain to them the logic flow. That process may get you to realise where the issue is.
 
Upvote 0

Forum statistics

Threads
1,215,970
Messages
6,127,991
Members
449,414
Latest member
sameri

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