X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Parsing Each Digit Of A Date Field To A Separate Field, Access 2016    
post Jan 11 2018, 04:53 PM

Posts: 2
Joined: 11-January 18

For purposes of an old Word form I have to merge data to that has/requires a field for each digit of a date in mm/dd/yyyy format, I want to be able to enter the date once into a field in my table/form [Req_Date] and then have each digit of the date in mm/dd/yyyy format (inlcuding leading zeros) be parsed into the following correlating fields in the table that ultimately get merged into a word form, those fields being Month1, Month2, Day1, Day2, Year1, Year2, Year3, Year4. I've looked around but havent been able to find code that will do exactly that. I found code that can extract the day as a single value (i.e. 15) but not the day into two separate fields like 1 and then 5. I'm trying to prevent users from having to enter all these digits into these fields manually, instead have them choose a date for the Req_Date field and then that value gets parsed automatically by each digit through code into all of these other fields.
Go to the top of the page
post Jan 11 2018, 05:02 PM

Posts: 936
Joined: 12-November 03
From: Iowa Lot

dim sDate as variant
dim Month1...

sDate = Forms![my form field]
if nz(sDate,"") <> "" then
Month1 = mid(sDate, 1, 1)
Month2 = mid(sDate, 2, 1)
end if

or if you can use an array

for I = 1 to 8
digit(i) = mid(sDate,i,1)

you may have to use Eval() for the form to convert the control value as string to a date value.
sDate=Eval(forms![my form field])
This post has been edited by kfield7: Jan 11 2018, 05:07 PM
Go to the top of the page
post Jan 12 2018, 12:08 PM

Posts: 2
Joined: 11-January 18

My question as to your code is where in the data entry form would this code go? (i.e. what form event or should it be in an event like AfterUpdate in the control such as the txtReq_Date control where I set the date?) So in other words in my data entry form there is a text box/date chooser for Req_Date and then there is a text box for each digit value of the date that can be printed out onto the Word doc in a merge. txtMonth1, txtMonth2, etc. It seems like your code can't fire up and do the parsing until a value has been set or chosen in the form's txtReq_Date field.
Go to the top of the page
post Jan 12 2018, 12:35 PM

Posts: 1,341
Joined: 26-December 12
From: Western Ma.,L.I.,N.Y.,Jupiter,Fl.

you would probably want to use afterupdate of the control or a button click event. Its hard to say as this seems an unusual request and we dont know your data entry process.

if you named your 8 textboxes something like dte1,dte2,dte3, etc. you could code it like this
Private Sub ParseDate()
    Dim i As Integer
    Dim txtdate As String
    txtdate = Format(Me.dteDate, "mmddyyyy")

    For i = 1 To 8
        Me.Controls("dte" & i) = Mid(txtdate, i, 1)
    Next i

End Sub

This post has been edited by moke123: Jan 12 2018, 12:36 PM
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    21st March 2019 - 04:47 AM