0

I created a userform to enter data into a large database. I want the format for dates (and currency $xxx.xx) to format to a proper default.

I want the date entries to display as: mm/dd/yyyy

For example if the user enter enters 3/16 in the UserForm, enter the full date of: 3/16/2019 INTO the database.

Do I need a variable on top? The things I've tried have said, "Variable Not Defined".

Community
  • 1
  • 1
DeniR
  • 11
  • 6
  • Be sure to check out the [Help Center](https://stackoverflow.com/help) for tips on [How to ask a good question](https://stackoverflow.com/help/how-to-ask) amongst other useful tips for this site as your question lacks a few requirements in it's current form. – Samuel Everson Mar 17 '19 at 06:08

1 Answers1

1

I figured this one out!! :^) Be sure to change the Txt Names to your database...

CURRENCY:

Private Sub Txt_Estimate_Amt_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'Estimate_Amt FORMAT
Me.Txt_Estimate_Amt = Format(Txt_Estimate_Amt, "$#,##0.00")
End Sub

PHONE:

Private Sub Txt_Client_Phone_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'Txt_Client_Phone FORMAT
Me.Txt_Client_Phone = Format(Txt_Client_Phone, "###-###-####")
End Sub

DATE:

Private Sub Txt_Invoiced_Date_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'Invoice Date FORMAT
Me.Txt_Invoiced_Date = CDate(Me.Txt_Invoiced_Date)
End Sub

TODAY'S DATE:

Private Sub Txt_Date_Recvd_Change()
  Txt_Date_Recvd = Format(Now(), "Short Date")
End Sub
DeniR
  • 11
  • 6
  • Please take a few minutes to figure out how to correctly format code when posting. – Tim Williams Mar 17 '19 at 06:10
  • 1
    Well done on figuring out a solution! As you mentioned you are a newby..., be careful using `on error resume next` as you are telling your code to ignore any errors, whilst this does have it's place you'd be better off handling your errors. To learn more you can read about error handling [here](https://stackoverflow.com/questions/1038006/good-patterns-for-vba-error-handling) among other SO posts and/or google searches. – Samuel Everson Mar 17 '19 at 06:17
  • WOW! Thank you Samuel! Oh my! I didn't realized that!!! I just took that line out "on error resume next" and it still works! Apparently, I didn't even need it! Thanks for your tip/link, that was and will be helpful! And thanks for your patience in realizing I'm just a beginner! The userform I've created is my 1st attempt at doing VBA! And it's all thanks to people like you who really desire to help! I still have a couple glitches/challenges, but I know, with support from others like you, I will complete it! :) – DeniR Mar 17 '19 at 16:22
  • I corrected the code above, to what I BELIEVE is the CORRECTLY Formatted code. It's working w/o the added line: "on error resume next" – DeniR Mar 17 '19 at 16:24