Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InfoPath formatting Date

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
Hello,

Basically I want this displayed at the top of my infoPath form. So if I open the form on a Tuesday and save it, it will still say the below. Also when i reopen the form, that should not change. It should only be updated when I start a new form.
Like this
Week#: 41 --- Starting: Monday, October 9, 2006

or Like this
Week#: 41 ---- September 9 thru September 15 2006

It's only easy when you know how.
 
Is the problem obtaining the dates in the correct format?
If so the following might help:

Code:
Sub Dt()
dt1 = Date
wk = Int((dt1 - DateSerial(Year(dt1), 1, 1)) / 7)
start_date = dt1 - (Day(dt1) - 2) 'the -2 may need amending depending on whether the week starts on a Monday or Sunday
str1 = "Week#: " & wk & " --- Starting: " & Format(start_date, "dddd, mmmm d, yyyy")
str2 = "Week#: " & wk & " ---- " & Format(start_date, "mmmm d") & " thru " & Format(start_date + 7, "mmmm d yyyy")
MsgBox str1
MsgBox str2
End Sub

All you need to do is pick the format you want and write it into the correct cell/textbox (depending on whether your form is a Form) if it is non-empty, when your form is selected.


Dirk

Everything useful perishes through use....Should I not rejoice at being useless?
 
Where do I put this code? I'm not a programmer and I just started using InfoPath. Actually it would be even better if I could do this:
I have two fields called dteDate and numWeek. I have the default value of numWeek set to @dteDate and I also have the check box for "Update this value when the result of the formula is recalculated" checked. Now when I select a date in the dteDate field it also inserts the date in the numWeek field. Now how do I format the result to display the week number instead of the date? I'm not sure where to insert the code you suggested. I'm not a programmer and just started using InfoPath. Thanks

It's only easy when you know how.
 
To be quite honest, if you really want to use Infopath, you need to do some programming - the user interface is pretty awful and a lot of things can only be done using code (design the infopath form in a .NET environment)

Have a look at the formulae available in Infopath - you may be lucky with this one if there is a WeekNum type formula which you can apply. Other than that, to manipulate dates in Infopath requires the byulding of a VB function in most instances

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top