+ Reply to Thread
Results 1 to 11 of 11

VBA Coding upon error message

  1. #1
    Registered User
    Join Date
    03-21-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    21

    VBA Coding upon error message

    I've created a form that when the user clicks submit, they get an error message if one of the fields are blank. The issue is that the rest of the fields populate. What I want the VBA to be able to do is go back to the form with all previous information still present so the user can fill in whats missing, but the rest of the information isn't populated on the excel spreadsheet.

    If this is too hard, or can't be done, I want it to be able to clear the form with an error message but again, nothing populates.

    Hope you guys can help me with this one.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    This could be straightforward, it depends on what code you currently have?

    Can you post that?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-21-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    21

    Re: VBA Coding upon error message

    If you can solve this I would be very gratful. Also if you see a way of streamlining this coding, again I would be grateful. Until 2 weeks ago I new nothing about VBA/Macros and have self taught. Think I've ceilinged on this one. lol

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-21-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    21

    Re: VBA Coding upon error message

    Can someone comment, if they are looking into my query, even if not solved yet so I know that it's got attention. TY

    BUMP
    Last edited by knighty2002uk; 03-21-2013 at 11:18 AM. Reason: back on first page for greater visibility

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Coding upon error message

    Only just had a chance to have a look at the code.

    The main problem is the order of the code.

    All the code that puts values on the worksheet should be after the code that validates the controls.

    The other thing you need to do is exit the sub if there's a problem with one of the controls.

    You'll also want to set focus on the control with the invalid data.

    So you would want to change an If like this,
    Please Login or Register  to view this content.
    to this.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-21-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    21

    Re: VBA Coding upon error message

    Thats worked 1/2 the problem out where I want the document to remain open with the information still present but it's still populating 1/2 the form when I click submit. Until all boxes are filled, I don't want it to populate anything.

    Thanks so far for the help Norie, hope we can close this one soon

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    How exactly did you change the code?

  8. #8
    Registered User
    Join Date
    03-21-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    21

    Re: VBA Coding upon error message

    This has been replicated through all text box command lines. Just posted one to save space.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    You still have the code to populate the worksheet before the code that validates the control.

    All the If statements should be at the top of the sub and the code to populate the worksheet should come next.

    I can't post the code for that right now, not at a computer.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Coding upon error message

    This is the sort of thing I mean.
    Please Login or Register  to view this content.
    You mentioned streamlining the code? One way you could do that is to exchange the 12 month checkboxes for one multiselect listbox set to display checks for each month.

  11. #11
    Registered User
    Join Date
    03-21-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    21

    Re: VBA Coding upon error message

    OMG, I just didn't think about the logical order of the coding. You are so right, that is fantastic. Your assistance and advice has been spot on. Many thanks Norie.

+ 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