Excel VBA Userform Date issue

Anonymous
2020-05-12T23:24:57+00:00

I am creating an excel database populated by a userform - the userform can also be re-populated with the data from the spreadsheet for later editing, deletion printing etc.Te issue is that the textbox populates the relevant cells in the correct dd/mm/yyyy UK regional format - however if the data contains a leading xero eg-02/08/2020 the value on the user form is returned as a numerical string - any other dates with a leading number of 1,2 or 3 such 21/09/2020 works fine The spreadsheet cells are all formatted correctly with a data format as above - Ive tried everything I can find and think of - can you advice pleaseABrown

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

62 answers

Sort by: Newest
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2020-05-17T05:36:56+00:00

    Lastly can I create a list on a user form which adds items each a new item is added from a combobox list without creating a complete new record every time a new item is added- thinking of a way to explain

    • it would be like shopping online where your online shopping basket acts like a list box and then copies all those items when your finished onto the worksheet when you press SAVE

    That is a complex problem, but solvable.

    You need to create a database in memory, I suggest to use a Scripting.Dictionary as container. (You can also use an array or collection or temporary sheet, but IMHO that is much more complicated).

    Inside that container, each record has to be an array, for your case you can use a simple one dimensional array, because that can be written very easy into a row in a sheet.

    All your routines inside the form must use this array (record) instead of cells to store the values.

    If you're done with the input in the form, simply add the record to the container. Update the Listbox with all keys that are currently inside the container.

    Finally if you want to save the data to the sheet, you have to get all data from the container and write each array into a row.

    I am not sure if this guide will help you, in any case it means that you have to discard your previous code.

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2020-05-16T14:20:32+00:00

    Adrian,

    I don't know how I can help you there.

    I thought I made it clear and showed you the errors that are already in your code and in your database. I showed you how you can use and evaluate a real date instead of a text.

    You have declined this and want to use text and the solution that Ossie suggested. That's ok for me.

    But, IMHO, this solution will never work for this purposes. So I can't give you any suggestions, I'm sorry.

    Andreas.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-05-16T13:02:20+00:00

    Hi Andreas

    I think im well aware of how to use a change event thank you 

    My question is regarding the code i need on the user form - also the other point regarding the list box please

    Was this answer helpful?

    0 comments No comments
  4. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2020-05-16T06:50:10+00:00

    is there away to carry out that calculation while the user is inputting the data for each each a new incident record is generated?

    You can use the Change event of a Textbox to execute a code while the user is typing.

    Choose the related Textbox on the left and the Change event on the right drop down.

    Andreas.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2020-05-15T17:28:46+00:00

    Hi Andreas and Ossie

    Thank you both for assistance

    Andreas - yes I know text was incorrect but that was the point of the original help request because text actully does work up to an extend until you have a date leading with 0 - I posted to the request to seek assistance with that issue which Ossie resolved and correctly in respect of the UK format

    So stepping back - regarding the the post in respect of using passive vba (rather than a command button on the user form) or a formula in the workbook - is there away to carry out that calculation while the user is inputting the data for each each a new incident record is generated?

    Lastly can I create a list on a user form which adds items each a new item is added from a combobox list without creating a complete new record every time a new item is added- thinking of a way to explain - it would be like shopping online where your online shopping basket acts like a list box and then copies all those items when your finished onto the worksheet when you press SAVE

    Was this answer helpful?

    0 comments No comments