+ Reply to Thread
Results 1 to 5 of 5

exception to MsgBox

  1. #1
    L Scholes
    Guest

    exception to MsgBox

    I am currently running this code to prevent users from leaving a
    TextBox (txtPO) empty:

    If Trim(Me.txtPO.Value) = "" Then
    Me.txtPO.SetFocus
    MsgBox "Please enter a Purchase Order Number."
    Exit Sub
    End If

    I would like this to only apply if "A," "B," or "C" are entered into
    cboDealer which is on the same user form. Otherwise I want the user to
    be able to leave this TextBox Empty. Can anybody provide me the
    appropriate code?

    Thanks in advance for all of your help!


  2. #2
    Tom Ogilvy
    Guest

    Re: exception to MsgBox

    Dim s as String
    s = Trim(Me.cboDealer.Value)
    if Len(s) = 1 and instr(1,"ABC",s,vbTextCompare)>0 then
    If Trim(Me.txtPO.Value) = "" Then
    Me.txtPO.SetFocus
    MsgBox "Please enter a Purchase Order Number."
    Exit Sub
    End If
    End if

    --
    Regards,
    Tom Ogilvy


    "L Scholes" <[email protected]> wrote in message
    news:[email protected]...
    > I am currently running this code to prevent users from leaving a
    > TextBox (txtPO) empty:
    >
    > If Trim(Me.txtPO.Value) = "" Then
    > Me.txtPO.SetFocus
    > MsgBox "Please enter a Purchase Order Number."
    > Exit Sub
    > End If
    >
    > I would like this to only apply if "A," "B," or "C" are entered into
    > cboDealer which is on the same user form. Otherwise I want the user to
    > be able to leave this TextBox Empty. Can anybody provide me the
    > appropriate code?
    >
    > Thanks in advance for all of your help!
    >




  3. #3
    L Scholes
    Guest

    Re: exception to MsgBox

    In your code you have "ABC" on line 3. When I substitute for my list,
    should I include the names without spaces or commas within one set of
    quotes, or list each separately in their own quotes, separated by
    commas?


  4. #4
    Tom Ogilvy
    Guest

    Re: exception to MsgBox

    You asked a specific question and got a specific answer. It the choices are
    not "A" "B" or "C", then the answer isn't appropriate

    If the choices are actually three text strings of multiple characters than
    checking for a len of 1 is inappropriate.

    Dim s as String
    s = "#" & Trim(Me.cboDealer.Value) & "#"
    if instr(1,"#AAAAA#BBBBB#CCCCC#", _
    s,vbTextCompare)>0 then
    If Trim(Me.txtPO.Value) = "" Then
    Me.txtPO.SetFocus
    MsgBox "Please enter a Purchase Order Number."
    Exit Sub
    End If
    End if

    Replace AAAAA, BBBBB, and CCCCC with your text strings.

    --
    Regards,
    Tom Ogilvy




    "L Scholes" <[email protected]> wrote in message
    news:[email protected]...
    > In your code you have "ABC" on line 3. When I substitute for my list,
    > should I include the names without spaces or commas within one set of
    > quotes, or list each separately in their own quotes, separated by
    > commas?
    >




  5. #5
    L Scholes
    Guest

    Re: exception to MsgBox

    Thank you sir, that works PERFECTLY!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1