joseph
joseph

Reputation: 17

VBA MS Access changing values in a textbox in between 2 characters

I am working on some forms in MS Access and I have lots of date data that I needs to change.

I have a date field that looks like this: 2/28/2019 10:00:00 PM. This field is loaded into a textbox called txtFieldDate.

Now I want to change the values in between the 2 slashes / / into 15. Now the date that is loaded can have a day value anywheres from 1 to 31 as we know, so the problem is for days 1 to 9, which are single digits (ex 2/4/2019 11:00:00 PM).

I tried using the replace function (ex. varMiddleDate = Replace(varMiddleDate, "/*/", "/15/")) but I cannot get wildcards working so I was wondering is there an easy way to replace whatever is in between the 2 slashes (one or two digits) and put the value 15 in there?

Thank you

Upvotes: 1

Views: 112

Answers (1)

Gustav
Gustav

Reputation: 55816

Never store date/time as text.

So, convert to DateTime and replace the Day value with 15:

TrueDate = CDate(YourTextDate)
Date15 = DateSerial(Year(TrueDate), Month(TrueDate), 15) + TimeValue(TrueDate)

Upvotes: 3

Related Questions