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: Most helpful
  1. Anonymous
    2020-05-28T11:27:07+00:00

    latest version to review

    Hi Ozzie

    Well I tried your options as best as I could and some it works when saving to the worksheet from the userform- the list box also mirrors the correct input

    However while the [ hh] works in the cell formatting and shows times over 24 hours when the data comes back to the form - even if I try and add a format to the 'Edit' script the format is lost an the value if over 24 hours shows zero in this format 00:00 

    ps the firefighting time is from 'Arrival time' to finished date and time - not from the call time

    Also Im still having to swap the dd/mm/yyyy to mm/dd/yyyy to get that to show correctly on the user form ( in edit) and worksheet as dd/mm/yyyy - the formular bar continues to show mm/dd/yyyy but maybe Ill just have to live with that as i just cant work out what to do when the user form date data is passed back to the spreadsheet

    Ive added my latest attempt as above and changed the labels to english so you can see - I cant really re translate all the other stuff and to be honest its not that much relevant to the issue - Ive added a line in the list box though so you can see both arabic and english

    If your not seeing the arabic text you will need to change the unicode to arabic uae - which is under administrator tab in the regional time date settings and doesnt affect your other settings - dont tick the beta unicode box if its there though or it will not work - sorry if you already know this 

    1/from window key- type region, choose admin tab, under language for non unicode - select change system locale- select arabic uae - restart 

    can you please just run your eye over everthing in the module and user form scripts to check if theres anything ive done wrong 

    Thank you 

    Adrian

    Was this answer helpful?

    0 comments No comments
  2. OssieMac 48,006 Reputation points Volunteer Moderator
    2020-05-27T10:42:21+00:00

    I need to be able to identify the date and Time TextBoxes so I know which TextBoxes to enter the data for testing purposes. Possibly I also need to be able to read the ListBox but not sure.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-05-27T09:11:59+00:00

    Hi Ozzie

    In process doing exacting what you suggest

    regarding an english version - I dont have that as only the text labels and drop downs - which arnt really relevant areand the msg box content are in arabic - the spread sheet is in both - which bit do you need in english?

    Was this answer helpful?

    0 comments No comments
  4. OssieMac 48,006 Reputation points Volunteer Moderator
    2020-05-27T04:42:02+00:00

    I suggest that you attempt to re-code using the Split and DateSerial functions anywhere you want to convert a Text date to an actual date and see how you go. If you want to upload examples for more assistance then I prefer that you create a English version for me to Download.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2020-05-27T00:07:28+00:00

    Hi Ozzie

    thank you for the explanation - I think it is close now!

    I think we may have crossed over on replies as I followed up to my first one as below

    Ok forget that last message - even though the script was wrong i still couldnt get it to work!!!!

    So Ive had a chance now to review your file and it works fine on my pc - all formats correct

    I just need to fiddle around with things to get it you work on my user form -

    If I add most of the script into my CMDSAVE macro will that work? if I add those lines before yje existing message box lines and call commands - will it work there? obviously the save function in my VBA Calls the "submit" script which transfer the entries to the worksheet so Ill have to work out how to do that  with out using the "With Worksheets etc part of your script -

    The elapsed time calculation needs to sit hidden in the background and not visible to the user on the user form as that is not part of the job role  - so Im thinking of still adding the relevant "tmetimedifference" box exactly as you suggest But just hide the box on the user sheet then add an appropriate line in the "submit" script e.g

    .Cells (Irow,xx) = etc

    as well as clearing on the "reset" script

    Any advice or tips on how to do that ?

    Thank you so much again

    Anyway I think if its possible to do the above stuff regarding adding the various parts from your example into my save script - do you think it will work? nly one way to find out

    Regarding the regional formats - theres nothing on my PC which is arabic other than the unicode setting but the problem was there before I did that change anyway

    However i did find out that using even regional settings that that CDate always tries to put it into US styles AND this can be tested where and this is my issue actually where the day is 12 or less - if the day is more than 12 then excel cant argue !!! as there is no 13th month - no body has a solution to this as I understand but I think we are there with how to explain and demonstrate the solution

    Thanks Adrian

    Adrian

    Was this answer helpful?

    0 comments No comments