Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-19-2004, 05:54 AM
JimmyS JimmyS is offline
Registered User
 
Join Date: Apr 2004
Location: here and there
Posts: 37
JimmyS is on a distinguished road
format to mmm-yy

This little bit of code is filling page header text boxes in a report with data from crosstab headers - its in the PageHeaderSection_Format section.

Code:
For intX = 1 To intColumnCount
        Me("Head" + Format$(intX)) = rstReport(intX - 1).Name
    Next intX
what I'm looking to do is format these text boxes as mmm-yy - they are dates in the format dd/mm/yy at the moment. I've added the code below ('for intx = 2' because the first column heading isn't a date) and it works but....

Code:
  For intX = 2 To intColumnCount
       Me("Head" + Format$(intX)) = Format(Me("Head" + Format$(intX)), "mmm-yy")
    Next intX
Ideally I would like the code to test if the value is a date and if it is set it to mmm-yy, also ideally in that same first bit of code where the headers are added to save a bit of time as the report creation is pretty slow already.

I want to be able to use this for other queries where the column headings may not be dates without having to alter the code.

jim
Reply With Quote
Sponsored Links
  #2  
Old 05-19-2004, 05:58 AM
namliam namliam is offline
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 7,791
namliam is just really nicenamliam is just really nicenamliam is just really nicenamliam is just really nice
You could offcourse if its allways this way... do this:

Me("Head1" ) = rstReport(0).Name
For intX = 2 To intColumnCount
Me("Head" + Format$(intX)) = Format(Me("Head" + Format$(intX)), "mmm-yy")
Next intX

Or if you really really need to check for a date use the functions IsDate()

Regards
Reply With Quote
  #3  
Old 05-19-2004, 06:06 AM
JimmyS JimmyS is offline
Registered User
 
Join Date: Apr 2004
Location: here and there
Posts: 37
JimmyS is on a distinguished road
Thanks - that will definately work for this instance - and is tidier than my adding another for..next loop - however I was thinking that perhaps I might have a crosstab where 1 or 2 or even all the column headers aren't dates so that's why I was thinking there must be a way to do the test...

jim
Reply With Quote
  #4  
Old 05-19-2004, 06:15 AM
namliam namliam is offline
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 7,791
namliam is just really nicenamliam is just really nicenamliam is just really nicenamliam is just really nice
Yep there is... as I also posted by using the IsDate([field]) function
Reply With Quote
  #5  
Old 05-19-2004, 06:37 AM
JimmyS JimmyS is offline
Registered User
 
Join Date: Apr 2004
Location: here and there
Posts: 37
JimmyS is on a distinguished road
doh ! sorry didn't see for looking - thanks for the suggestion

Now i'm going for the isdate option yet i'm struggling mixing if...thens with for...nexts.

Code:
 For intX = 1 To intColumnCount
   If IsDate(Me("Head" + Format$(intX)) = rstReport(intX - 1).Name) Then
   Me("Head" + Format$(intX)) = Format(rstReport(intX - 1).Name, "mmm-yy")        
  Else
      Me("Head" + Format$(intX)) = rstReport(intX - 1).Name
    End if
    Next intX

The dates don't change format

Last edited by JimmyS; 05-19-2004 at 07:00 AM..
Reply With Quote
  #6  
Old 05-19-2004, 07:13 AM
namliam namliam is offline
The Mailman - AWF VIP
 
Join Date: Aug 2003
Location: Amsterdam/The Netherlands
Posts: 7,791
namliam is just really nicenamliam is just really nicenamliam is just really nicenamliam is just really nice
For intX = 1 To intColumnCount
If IsDate(Me("Head" + Format$(intX)) = rstReport(intX - 1).Name) Then
Me("Head" + Format$(intX)) = Format(rstReport(intX - 1).Name, "mmm-yy")
Else
Me("Head" + Format$(intX)) = rstReport(intX - 1).Name
End if
Next intX

Oh come on your kidding right??? What is supposed to be date??? The Head thing right??? So only isdate(headthing)

If IsDate(Me("Head" + Format$(intX))) = rstReport(intX - 1).Name Then
Reply With Quote
  #7  
Old 05-19-2004, 07:18 AM
JimmyS JimmyS is offline
Registered User
 
Join Date: Apr 2004
Location: here and there
Posts: 37
JimmyS is on a distinguished road
cheer - the penny just dropped literally seconds before i saw your post....I was just about to post that i'd got it and I'm a fool

Thanks namliam

- i'll remember to be less swift to post my problems when a little break can make things clearer

Its been a long day of staring at the same few lines of code - something I do very rarely..

i wrote this and it works to test each column header for a date:

Code:
For intX = 1 To intColumnCount
        If IsDate(rstReport(intX - 1).Name) Then
        Me("Head" + Format$(intX)) = Format(rstReport(intX - 1).Name, "mmm-yy")
        Else
        Me("Head" + Format$(intX)) = rstReport(intX - 1).Name
        End If
   Next intX

thanks again for taking the time to post.

Last edited by JimmyS; 05-19-2004 at 07:21 AM..
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:02 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World