Consulting

Results 1 to 20 of 20

Thread: Form not working, Cracking me up!

  1. #1
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location

    Form not working, Cracking me up!

    Hi

    What's wrong with the form on this workbook?

    I complete it and what's supposed to happen is that it submits the entries onto a "Records" sheet, saves itself, unloads and reloads itself (to clear all the entries and reset the dropdowns).

    This worked fine but now it isn't. I click submit (for testing purposes, in the first box choose "inappropriate for test & learn" and that will allow you to submit the form with no further data entry). And I can see from the status bar that it has moved the data to the records sheet because it's saving (and the save instruction comes at the end). But it seems to be the unloading and the reloading. My PC hangs.

    All my users are getting problems (they each have a copy). Please can someone look through my coding and see what's going wrong?

    Also there is a macro called create agent sheets. It's supposed to just copy itself and rename itself after each agent in the list (on the sheet "agents"). It does this - but it ends up being over 2mb big - whereas the original is much smaller.

    Thanks

    BD
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You shouldn't try and reload it from within the form just after you unloaded it.

    In the module that launches the form, use

    [vba]

    Sub ShowToolkitForm()

    Application.Calculate
    FormRetentionToolkit.Show
    Unload FormRetentionToolkit
    FormRetentionToolkit.Show
    End Sub
    [/vba]

    In your code, how did you propose to end, as both submit and Cancel resubmit?

    and wouldn't it just be better to have a method that resets all of the fields and give a proper exit?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Thanks Bob

    Quote Originally Posted by xld
    You shouldn't try and reload it from within the form just after you unloaded it.
    I see. I'm a newbie with forms, but now I know.

    Quote Originally Posted by xld
    In your code, how did you propose to end, as both submit and Cancel resubmit?
    Sorry, not sure what you mean... My cancel button means "Cancel the current record" not "Close the form", reloading the form seemed to work well initially

    Quote Originally Posted by xld
    and wouldn't it just be better to have a method that resets all of the fields and give a proper exit?
    Probably, it just seemed quicker to re-initialise the form. But I guess I could just copy the code from the initialize bit a paste it to the end of submit and cancel.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Sir Babydum GBE
    Sorry, not sure what you mean... My cancel button means "Cancel the current record" not "Close the form", reloading the form seemed to work well initially
    I know that, but I couldn't see in your code (if it had worked) how you would ever unload the form.

    Quote Originally Posted by Sir Babydum GBE
    Probably, it just seemed quicker to re-initialise the form. But I guess I could just copy the code from the initialize bit a paste it to the end of submit and cancel.
    Create a method called Initialize with all that code it, and call that befor eyou show the form, and on Reset.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    I know that, but I couldn't see in your code (if it had worked) how you would ever unload the form.
    I just told the guys to click the x on the top of the form to close it at the end of their shift.

    Quote Originally Posted by xld
    Create a method called Initialize with all that code in, and call that before you show the form, and on Reset.
    I already have initialize, but I'll do what you suggest re calling it.

    Thanks again
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Personally, I would ALWAYS have a proper exit/unload button.

    And just to be sure, I mean a method called Initialize (Public Function Initialize), not the built-in event (Userform_Initialize).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    Personally, I would ALWAYS have a proper exit/unload button.
    Why? I'm not being cheeky - just curious.

    Quote Originally Posted by xld
    And just to be sure, I mean a method called Initialize (Public Function Initialize), not the built-in event (Userform_Initialize).
    i see what you mean - will do.

    Any ideas on why the 171kb workbook becomes a 2mb one when the form is used?
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It's a useability thing BD. Form design is an art, making sure that the key information is prominent, making sure that the navigational flow is good (for instance, it is generally considered to go left to right, row by row, not column by column as yours does), and that the form management is simple and intuitive. Most people think of buttons in this context, and having a button that clearly says Exit/Finish or whatever makes it all more obvious (not saying I am good at it, but I do at least try).

    Excel workbooks do bloat, and for some odd reason it bloats by far more than is added to the workbook. I always clean a project before shipping it, using the Code Cleaner app by Rob Bovey http://www.appspro.com/Utilities/CodeCleaner.htm
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Babydum,
    I am reading the chapter on Userforms in Wrox's book VBA2002. Chapter 13 has some stuff on this. I don't know if you can get a copy. I was looking around for a ebook that I could copy the pages to you, but have not found it yet. It deals w/ cancelling the form and closing down the form w/ the "X" button.
    Here are the snippets of code:
    [vba]
    Option Explicit
    Public Cancelled As Boolean

    Private Sub bnCancel_Click()
    Cancelled = True
    Me.Hide
    End Sub

    Private Sub bnOK_Click()
    Cancelled = False
    Me.Hide
    End Sub
    [/vba]

    I cannot find the "X" so this is typed from the book:
    [vba]
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode=vbFormControlMenu Then
    Msgbox "Please use only the OK or Cancel Buttons", vbcritical
    cancel = true
    end if
    end sub
    [/vba]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  10. #10
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    It's a useability thing BD. Form design is an art, making sure that the key information is prominent, making sure that the navigational flow is good (for instance, it is generally considered to go left to right, row by row, not column by column as yours does), and that the form management is simple and intuitive. Most people think of buttons in this context, and having a button that clearly says Exit/Finish or whatever makes it all more obvious (not saying I am good at it, but I do at least try).

    Excel workbooks do bloat, and for some odd reason it bloats by far more than is added to the workbook. I always clean a project before shipping it, using the Code Cleaner app by Rob Bovey http://www.appspro.com/Utilities/CodeCleaner.htm
    Ok, I see your point.

    Our firewall won't let me get the cleaner - oh well.

    One more question... In Initialize (the new one) is there a simple way of saying with vba: make everything except the frames enabled=false? Or do I need to name each component of the form, one at a time?

    Quote Originally Posted by YellowLabPro
    ...Here are the snippets of code...
    Cheers for that too!
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    On Error Resume Next
    For Each ctl In Me.Controls
    If ctl.Name <> "FrameName" Then
    ctl.Enabled = False
    End If
    Next ctl
    On Error Goto 0
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    [vba]

    On Error Resume Next
    For Each ctl In Me.Controls
    If ctl.Name <> "FrameName" Then
    ctl.Enabled = False
    End If
    Next ctl
    On Error Goto 0
    [/vba]
    That's odd: Though I can see the "For" with my very own eyes, I get an error saying "Next without For"
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  13. #13
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You must be missing some other terminating statement (e.g. End If) in another part of the code, or you have them out of sequence. (I'm assuming this has been put in amongst some other code?)
    Regards,
    Rory

    Microsoft MVP - Excel

  14. #14
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by rory
    You must be missing some other terminating statement (e.g. End If) in another part of the code, or you have them out of sequence. (I'm assuming this has been put in amongst some other code?)
    Nope - just ran the code on its own to test it
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  15. #15
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Works fine for me - you sure you didn't move the ctl.enabled = False line up onto the same line as the If... line?
    Regards,
    Rory

    Microsoft MVP - Excel

  16. #16
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    oops...

    Bob might kill me now for suggesting his code didn't work - I couldn't have pasted it properly. Sorry.

    (Just glad I don't live in the same town)
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  17. #17
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    you mean the same country!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  18. #18
    ahhhhh Bob is in Texas anyway....
    I think near Bush....
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  19. #19
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    you mean the same country!
    What, you really are in Chile?

    I always thought you were lying.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  20. #20
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by YellowLabPro
    ahhhhh Bob is in Texas anyway....
    I think near Bush....
    Dubblyaa is a good friend of mine. Actually Doug, I used to live in Austin Tx, great town.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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