+ Reply to Thread
Results 1 to 20 of 20

Excel Forms

  1. #1
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161

    Excel Forms

    I have a form in Excel that records data, its is an Order Form. On this is a column for Price. I have a number of rows for creating a Description of Goods, Qty & Price. These are all as a Text Box. At the bottom is a Total Box, this is as a Label.

    What I am trying to do is after the Text Boxes have had a value input is to calculate the Total Price as we go along. How do I get this to work?

    This is what I have been doing....
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    when inputting a Price in the Text Boxes it comes back with Type Mismatch and highlights Sub TotalCalc. I got as far as inputting 2 Price in when the Type Mismatch came up.

    What can that be for?

    Also lblTotal will still not add them up but just keep putting whatever is in the TextBoxes, eg 55555

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    TextBox entries are by default strings, you need to convert them with CLng
    Please Login or Register  to view this content.
    You can actually combine it all into one Procedure
    Please Login or Register  to view this content.
    Last edited by royUK; 06-06-2008 at 08:32 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    I've tried the rejigged code and I still have an issue with it. Everytime I input a number in the Price TextBox is brings up the Error MsgBox, and doesnt Total the lblTotal.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Where am I going wrong?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You might get an error message if any textbox is empty, it must have a value so set a default value of zero,

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431
    You can condense your code

    Please Login or Register  to view this content.
    Also I notice your declared your variables as Double but are using the CLNG function which will lose the floating point information
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    Thanks for that, what do I delcare IngTotalPrice as of not a Double?

    I also need the ability to have empty TextBox's depending on whether an order is raised with so many products.
    Last edited by JezLisle; 06-08-2008 at 03:38 PM.

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    JezLisle,

    Please read forum rules below and then add the link to the cross post to the other forum

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  8. #8
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    I have tried a couple of thing of things with this...

    Firstly I have taken out the MsgBox line as I want to have the ability to leave any number of TextBoxes empty as they might not have an order. Also I tried this as well
    Please Login or Register  to view this content.
    When this run it still doesnt add up in lblTotal. This always stays as zero, If I change the Sub GetTotal to this below I get the Compile Error message: Member or Data Member not found (not sure what it means)
    Please Login or Register  to view this content.
    Also am I correct in thinking that for every TextBox that I have for putting a price in will need this code behind it?
    Please Login or Register  to view this content.
    As there are 25 TextBox then I have this for each indvidual TextBox.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please do as requested by VBA Noob & add the link

  10. #10
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Thanks

    Andy's code loops through each textbox & sums each one that contains a numeric value, converting it with cDbl(check VBA Help), if it not numeric it reports a non numeric entry. Maybe this change might work, if there is a non numeric value or blank it changes the value to zero. Test it & kllet us know.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    I have tried that new code and when I run the form it still shows in the lblTotal as a zero, am I correct in having this as a label or should it be a TextBox?

    Also do I need the Sub GetTotal() and the Private Subs txtPrice1_ AfterUpdate() 1 to 25, because if I do then I get the Compile Error message: Member or Data Member not found

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    A label's fine for the result. Can you attach a sample workbook with your userform in? Please zip it first as sometimes unzipped workbooks don't download correctly.

  14. #14
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    This is a copy of the Excel Database with Forms
    Attached Files Attached Files

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You weren't using the code that i could see, you still had this in use.

    Please Login or Register  to view this content.
    You didn't declare lngTotalPrice, I have done this but changed it a Currency


    Please Login or Register  to view this content.
    I think the attached does what you want, but the rest of the code could be streamlined, see the amended code for cmdAdd:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by royUK; 06-10-2008 at 03:38 AM.

  16. #16
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    Thanks Roy, I hadnt changed the Sub GetTotal() as I didnt quite understand what you had done and only changed the Module on TotalPrice...

    When I try run it comes up with Next without For what does that mean?

    I will have a look at streamlining the other code now you have amended the cmdAdd. I've learnt something there that I didnt know. Thankyou

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I've just checked the code & I deleted a wrong line. I have uploaded an amended file.

    I think your code lines could be reduced tremendously if you use the Loop through controls method.

    What Database do you send the forms to/ Is an access database/ just wondering why yo don't build the form within the database.

  18. #18
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    Ok cool, will have a look now

    Thanks Roy.

    I dont know that much about using the forms in Excel its the first time I have used it properly like this.

    All the data is then sent to an Access Database where its stored and I can build some reports for the Management to look at and review spending and so forth. I'd love to have built this directly in Access as it would have been far easier and much better. The problem being is that the Company I work for do not allow people to create their own database, it has to come through the IT department, and also they apparently dont have anyone to support it if it falls over. Why thats necessary when I would have built it I dont know.

    The other reason is that every user on the network doesnt have MS Office Proffesional loaded onto their PC. Its the bog standard one, and to upgrade it apparently would cost thousands just for a small number of users.

    So I have to grin and bare it. Not really much I can do. Already complained somany times that dont have enough tools do my job

  19. #19
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You can reduce code in the cancel button like this

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    06-06-2008
    Location
    Manchester
    MS-Off Ver
    MS Office 2003
    Posts
    161
    Wow that really reduces all that code

    Thanks for that.

    Also the lblTotal now adds up too, chuffed now that works :D

    Thanks again, no doubt I will be back again soon with another issue.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. SharePoint and Excel Macro Interactivity
    By maverick_abhi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-17-2011, 04:09 PM
  2. Excel 2007: OpenDatabase fails to connect to a SQL database
    By jpc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2007, 09:36 AM
  3. excel data forms
    By phillb in forum Excel General
    Replies: 8
    Last Post: 06-20-2007, 10:24 AM
  4. processing a string by Excel
    By mark_neil2 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-20-2007, 07:35 AM
  5. Converting Excel forms to a new layout
    By MikeM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2007, 04:32 PM

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