Format Date as Day. Mon, Tue, Wed etc (1 Viewer)

RainLover

VIP From a land downunder
Local time
Today, 22:01
Joined
Jan 5, 2009
Messages
5,041
I have no idea what I am doing wrong here.

I have a Query.

DateTracked is a field from the Table. It is of Data Type Date/Time, Formatted as Medium Date.

There are other Fields. Like Breakfast, Lunch and Dinner.

Problem.

I want to display in a separate Column "DateTracked" as a day of the week.

I have the following:

MyDate: Format ([DateTracked], "ddd")

This should display the day of the week as Mon, Tue, Wed etc.

What is it that I am doing wrong.

:banghead:
 

JHB

Have been here a while
Local time
Today, 14:01
Joined
Jun 17, 2012
Messages
7,732
What do you get then?
 

RainLover

VIP From a land downunder
Local time
Today, 22:01
Joined
Jan 5, 2009
Messages
5,041
I get an error message.
It says that it contains a syntax error.

Could it be because I am Formatting a Field that I got directly from the Table.

I will send a copy in a minute or two.

Just need to cut this one down.
 

RainLover

VIP From a land downunder
Local time
Today, 22:01
Joined
Jan 5, 2009
Messages
5,041
You will have to put the Format code back into the Query.

I cannot save while it is there.

A Copy of the code is in the Remarks of the table.
Now this is strange. I opened this post in advanced mode and got all these </p>.

These do not show up when the post is displayed.

Perhaps I have some corruption. Not sure
 

Attachments

  • RainLover Ver 2003.zip
    13.6 KB · Views: 69

Brianwarnock

Retired
Local time
Today, 13:01
Joined
Jun 2, 2003
Messages
12,701
That space between Format and ( doesn't exist in the code does it? If so could that be the problem.?

Brian

PS I no longer have Access, just browsing.
 

RainLover

VIP From a land downunder
Local time
Today, 22:01
Joined
Jan 5, 2009
Messages
5,041
Thanks Brian but that is not it.

Tomorrow I will build a new Database from scratch and try again.

It is too close to my bed time to start now.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:01
Joined
Sep 21, 2011
Messages
14,256
It works for me OK?

I just entered MyDate:Format(DateTracked,"ddd")

and let Access add the []

DB attached

Code:
MyDate: Format([DateTracked],"ddd")
 

Attachments

  • Working RainLover Ver 2003.zip
    16 KB · Views: 81
  • rainloverquery.jpg
    rainloverquery.jpg
    96.3 KB · Views: 73

stopher

AWF VIP
Local time
Today, 13:01
Joined
Feb 1, 2006
Messages
2,395
I had to comment out AbosolutePosition in the code window to get it to work.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:01
Joined
Sep 21, 2011
Messages
14,256
I had to comment out AbosolutePosition in the code window to get it to work.

Damn, so did I when I was writing my own function. Forgot about that. Sorry.:banghead::eek:
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:01
Joined
Aug 30, 2003
Messages
36,125
Gasman, don't know if you added the function, but the reason it wouldn't have worked is the name mismatches:

Code:
Function [COLOR="Red"]MyDay[/COLOR]([COLOR="Magenta"]dtDate[/COLOR] As Date)
    [COLOR="red"]MyDate[/COLOR] = Format([COLOR="Magenta"]stDate[/COLOR], "ddd")
End Function
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:01
Joined
Sep 21, 2011
Messages
14,256
Cheers,

I did start my own function just to see if that would work. However I went back to Rainlover's way and did it in the query, however I forgot I deleted that 'AbsolutePosition' line as it was in black, and I had no idea what is was meant to indicate.:eek:

If I had used that function, I would have found my error. Just did not remove it as was now not relevant.

Although I must admit having seem some references to Format and missing references in this forum, and the fact that Rainlover also had 2007 I was *thinking* that might be the cause.

Still learning, as you can see. Still keen to learn though. :D
 

RainLover

VIP From a land downunder
Local time
Today, 22:01
Joined
Jan 5, 2009
Messages
5,041
Gasman, don't know if you added the function, but the reason it wouldn't have worked is the name mismatches:

Code:
Function [COLOR=red]MyDay[/COLOR]([COLOR=magenta]dtDate[/COLOR] As Date)
    [COLOR=red]MyDate[/COLOR] = Format([COLOR=magenta]stDate[/COLOR], "ddd")
End Function


Paul

A UDF is not really what is was chasing.

I really want to know why the Code would not work in a Query.

Thanks.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:01
Joined
Aug 30, 2003
Messages
36,125
I think they've resolved that it does work directly in a query, I was just pointing out the error in the UDF in case someone was trying to get it to work and failed.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:01
Joined
Sep 21, 2011
Messages
14,256
I realise that.:eek:

I was creating that, only to see if it worked via a UDF of my own making. That was due to some threads here also having problems with the Format function and references.

However I then decided to see if it worked for me directly in the query anyway and then forgot all about that function.

I have discovered from this thread, that even having incorrect code in a module can cause your problem, so that has been beneficial to me.

I had not added Option Explicit, so fortunately my code would not upset anything?, or so I believe.

Paul

A UDF is not really what is was chasing.

I really want to know why the Code would not work in a Query.

Thanks.
 

RainLover

VIP From a land downunder
Local time
Today, 22:01
Joined
Jan 5, 2009
Messages
5,041
I had not added Option Explicit, so fortunately my code would not upset anything?, or so I believe.

Option Explicit should be used all the time.
 

Users who are viewing this thread

Top Bottom