UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Get Week Day Into Code, Access 2013    
 
   
wizcow
post Sep 30 2017, 06:11 PM
Post#1



Posts: 301
Joined: 10-April 03
From: B.C. Canada


Hello

I am using code to fill a label on a form.
The label displays the day of the week.

Private Sub UpdateClock()
currentDate = Now()
Me!LabelDay.Caption = Format(currentDate, "dddd")
End Sub

Resulting in the label displaying the word Saturday

This is perfect...

I am now trying to use the result from the label in code.

Private Sub Form_Timer()

If frmSwitch!LabelDay = "Saturday" Then
GetMail
End If

End Sub

...but this doesnt work.
Anyone see what I am doing wrong?
Go to the top of the page
 
theDBguy
post Sep 30 2017, 06:37 PM
Post#2


Access Wiki and Forums Moderator
Posts: 73,769
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Is the problem code inside the same form where the label is located? If so, replace the line:

If frmSwitch!LabelDay = "Saturday" Then

with this:

If Me.LabelDay = "Saturday" Then

to see if it makes a difference. However, you can also simply repeat the same expression in your code. For example:

If Format(Date(), "dddd") = "Saturday" Then

Or, another approach might be something like this:

If Weekday(Date()) = 7 Then

Hope it helps...
Go to the top of the page
 
wizcow
post Sep 30 2017, 11:11 PM
Post#3



Posts: 301
Joined: 10-April 03
From: B.C. Canada


Thank you TheDBguy !

I am trying to collect the date from a different form. (frmSwitch)
The code is ran from (frmMail) both are open.

When I run the code I get this error
frmSwitch!LabelDay = <object required>

I tried using
If frmSwitch!LabelDay = vbSaturday Then
but it didnt work either

I was hoping it would be just a syntax thing smile.gif

Thank you for the help!!!
Tom
Go to the top of the page
 
cheekybuddha
post Oct 1 2017, 06:08 AM
Post#4


UtterAccess VIP
Posts: 10,546
Joined: 6-December 03
From: Telegraph Hill


>> I was hoping it would be just a syntax thing smile.gif <<

It is!

It's a label, and you've forgotten to access its .Caption property:
CODE
Private Sub Form_Timer()

  If frmSwitch!LabelDay.Caption = "Saturday" Then
    GetMail
  End If

End Sub


Beware, you might want to set TimerInterval = 0 after calling GetMail, unless the intention is to continuously fire that function each TimerInterval on a Saturday.

hth,

d
Go to the top of the page
 
wizcow
post Oct 3 2017, 06:39 PM
Post#5



Posts: 301
Joined: 10-April 03
From: B.C. Canada


Awesome!
Thank you CheekyBuda
Good call on the timer.
If the interval is set to 0 will it fire again next saturday?
I want it to launch once every saturday.

Thanks
Tom
Go to the top of the page
 
cheekybuddha
post Oct 3 2017, 07:09 PM
Post#6


UtterAccess VIP
Posts: 10,546
Joined: 6-December 03
From: Telegraph Hill


Well, it depends on what the TimerInterval is set to!

If it fires once an hour, it could call GetMail() 23/24 times each Saturday!
Go to the top of the page
 
wizcow
post Oct 4 2017, 08:57 AM
Post#7



Posts: 301
Joined: 10-April 03
From: B.C. Canada


Of course!
Thanks Dave
Go to the top of the page
 
wizcow
post Oct 4 2017, 12:49 PM
Post#8



Posts: 301
Joined: 10-April 03
From: B.C. Canada


I just discovered a new problem...

I want to use an array with seven radio buttons (sunday, monday tuesday, wednesday, thursday, friday and saturday)

I would like to select say, the monday radio button.
When labelDay clicks over to monday it will run my mail code.

The problem I have now is labelDay.format = 'dddd'
so the value it returns is 'Monday"
The array returns returns 2 as a value.

I was wanting to do something like this as code...

If labelDay = arrayDay then
run mailer
endif

Of course this doesnt work because arrayDay is returning a number and labelDay is returning text.

Is there a better way to do this?

Thansk
Tom
Go to the top of the page
 
cheekybuddha
post Oct 4 2017, 12:53 PM
Post#9


UtterAccess VIP
Posts: 10,546
Joined: 6-December 03
From: Telegraph Hill


Have a look at the last suggestion in DBguy's Post#2, and perhaps forget labelDay.Caption
Go to the top of the page
 
wizcow
post Oct 4 2017, 09:35 PM
Post#10



Posts: 301
Joined: 10-April 03
From: B.C. Canada


Cheekybuda

Of course. Thank you!

I think i am almost there:)

As a test
I triggered a message box to show the results

MsgBox (optDay & Weekday(Date))

And it returns 44 which is perfect, but...
when I add it into an if statement, I get no result.

If Me!optDay = Weekday(Date) Then
MsgBox ("thats it")
End If

So optDay is returning the value of 4
and Weekday(date) is returning the value of 4
Does anyone see why the if statement does not work?

Thank you
Tom
Go to the top of the page
 
theDBguy
post Oct 4 2017, 09:43 PM
Post#11


Access Wiki and Forums Moderator
Posts: 73,769
Joined: 19-June 07
From: SunnySandyEggo


Hi Tom,

What do you get if you use the following instead?

MsgBox Me.optDay
MsgBox WeekDay(Date)
MsgBox Me.optDay=WeekDay(Date)
Go to the top of the page
 
wizcow
post Oct 4 2017, 09:48 PM
Post#12



Posts: 301
Joined: 10-April 03
From: B.C. Canada


DBGuy

I get 4
then 4
then false

Tom
Go to the top of the page
 
theDBguy
post Oct 4 2017, 10:41 PM
Post#13


Access Wiki and Forums Moderator
Posts: 73,769
Joined: 19-June 07
From: SunnySandyEggo


Interesting... What do you get with this?

MsgBox CInt(Me.optDay)=Weekday(Date)
Go to the top of the page
 
wizcow
post Oct 5 2017, 08:42 AM
Post#14



Posts: 301
Joined: 10-April 03
From: B.C. Canada


Again 'False'
I tried using dim statements to change both values to a number, but got the same result.
Not sure why 4 does not equal 4 smile.gif
Go to the top of the page
 
theDBguy
post Oct 5 2017, 10:33 AM
Post#15


Access Wiki and Forums Moderator
Posts: 73,769
Joined: 19-June 07
From: SunnySandyEggo


Hi,

What exactly is optDay and how is it populated? Is it an Option Group, a Combobox, or what?
Go to the top of the page
 
wizcow
post Oct 5 2017, 12:45 PM
Post#16



Posts: 301
Joined: 10-April 03
From: B.C. Canada


DBGuy
It is an array with seven radio buttons (sunday, monday tuesday, wednesday, thursday, friday and saturday)

i want to be able select a day (eg. monday radio button) and an email will be sent every monday.

Also I no longer need to get the date from the other form frmswitch as the weekday(date) function gets todays date

Thanks
Tom
Go to the top of the page
 
theDBguy
post Oct 5 2017, 12:53 PM
Post#17


Access Wiki and Forums Moderator
Posts: 73,769
Joined: 19-June 07
From: SunnySandyEggo


Hi Tom,

An "array" could refer to more than one thing. Can you post a screenshot of your form in design view showing the properties of the radio buttons? Thanks.

For example, if it's an Option Group, we'll need to see the Option Value property.
Go to the top of the page
 
wizcow
post Oct 5 2017, 01:34 PM
Post#18



Posts: 301
Joined: 10-April 03
From: B.C. Canada


It is an option group, yes smile.gif
Attached File(s)
Attached File  Capture.JPG ( 61.42K )Number of downloads: 2
 
Go to the top of the page
 
theDBguy
post Oct 5 2017, 02:00 PM
Post#19


Access Wiki and Forums Moderator
Posts: 73,769
Joined: 19-June 07
From: SunnySandyEggo


Okay, thanks. Looks good so far. So, for today (Thursday), let's try the following in the AfterUpdate event of the Option Group:

MsgBox Me.optDay = Weekday(Date)

and select Thur. Do you still get a False? If so, are you able to post a small copy of your db without any data?

Click on the image below to see the MsgBox.

Attached File  option_group.gif ( 506.05K )Number of downloads: 3
Go to the top of the page
 
wizcow
post Oct 5 2017, 02:20 PM
Post#20



Posts: 301
Joined: 10-April 03
From: B.C. Canada


dbGuy

Still False
Ill prep a db for you

Thank you
Tom
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    20th November 2018 - 12:38 AM