Date String problem Macro won't run

I have combobox Cmbo_Header2 in a form that has a control source from a query that is a DatePart expression from [Work_Date] which is another field in my query. I want to make a macro run if the Datepart is a "Friday". Debugger is not giving me an error but my macro does not run. I tested the Macro by itself and it works. What am I doing wrong?
Private Sub Cmbo_Header2_BeforeUpdate(Cancel As Integer)
Dim StrFriDate As String
StrFriDate = Cmbo_Header2
FormStrFri = Cmbo_Headers.Format("dddd")
If FormStrFri = ("Friday") Then
StrFriDate = True
Else: StrFriDate = False
If StrFriDate = True Then
'Code below pops up a message box that say Yea it's Friday
DoCmd.RunMacro "Macro_it'sFriday"
Else
DoCmd.Beep
End If
End If
End Sub
Thanks
Nordite

Popular White Paper On This Topic

Nordite,
It looks similar to your previous post. The code to perform this is posted in that query. To use your code here, try the following. If you are still trying to turn the controls on and off depending on the date, you will need ot use the visible functionality. You can't tell a variable to be true or false unless it is a boolean.
Private Sub Cmbo_Header2_BeforeUpdate(Cancel As Integer)Dim StrFriDate As StringDim FormStrFri As String
Dim ItIsFriday As Boolean
'loads the date in the control
StrFriDate = Me.Cmbo_Header2'collects the date as the long Day
FormStrFri = Format(Me.Cmbo_Headers.Value, _
"dddd")If FormStrFri = ("Friday") Then

ItIsFriday = True

'hide controls - change to suit control names

txtWorkDate.Visible = False
Else: ItIsFriday = FalseEnd If
If ItIsFriday Then 'do not need = true
'Code below pops up a message box to say so

Allan and Phil,
Thanks to both of you for your helpful information. Here was what finally worked. I made one update query that adds 1 day to the current date Date()+1 and another that adds three days Date()+3. If it's "Friday" the correct update runs. I still don't understand why the code I wrote the first time around would not work in either the OnOpen, OnCurrent and any other event I tried.
Thanks again,
Nordite
Private Sub Form_Open(Cancel As Integer)
Dim StrFriDate As String
Dim FormStrFri As String
Dim ItIsFriday As Boolean 'loads the date in the control
'Text_Today_Date is the control on the form that I want the date to come from.
StrFriDate = Me.Text_TodayDate
'collects the date as the long Day
FormStrFri = Format(Me.Text_TodayDate.Value, "dddd")
If ItIsFriday = False Then
DoCmd.RunMacro "Macro_Update_Scheduling_Date"
If FormStrFri = "Friday" Then
ItIsFriday = True
If ItIsFriday = True Then
DoCmd.RunMacro "Macro_Cng_Friday_Date"
Else: ItIsFriday = False
End If
End If
End If

Nordite,
You can cut out a lot of your code by using the <> not equal to braces. You also need to place the date into the control by the looks but you may have it defaulting to the current date already. Your controls should still work in the header I think. I am not currently on my Access computer so I can't test the code but it should be all goood.
Regards,

Allan,
Thanks so much for your response. Your code worked good for making the msgbox work but I still can't get the controls on the form to be invisible. I kept trying different things and different events. The controls are in the Header of the form, could that make a difference? I got more specific with the code but know luck. I am wanting the controls in the form header to be visible or invisible depending on if the current day is "Friday". Could you please give it one more look?
Thanks,
Nordite
Dim StrFriDate As String
Dim FormStrFri As String
Dim ItIsFriday As Boolean 'loads the date in the control
'Text_Today_Date is the control on the fom that I want the date to come from.
StrFriDate = Me.Text_Today_Date 'collects the date as the long Day
FormStrFri = Format(Me.Text_Today_Date.Value, "dddd")
If FormStrFri = ("Friday") Then
ItIsFriday = True
If ItIsFriday = True Then
Me.Txt_Header2.Visible = True
Me.Txt_bx_DateHeader.Visible = False
'hide controls - change to suit control names
If FormStrFri = ("Monday") Then
ItIsFriday = False
If ItIsFriday = False Then
Me.Txt_Header2.Visible = False
Me.Txt_bx_DateHeader.Visible = True
If FormStrFri = ("Tuesday") Then
ItIsFriday = False
If ItIsFriday = False Then
Me.Txt_Header2.Visible = False
Me.Txt_bx_DateHeader.Visible = True
If FormStrFri = ("Wednesday") Then
ItIsFriday = False
If ItIsFriday = False Then
Me.Txt_Header2.Visible = False
Me.Txt_bx_DateHeader.Visible = True
If FormStrFri = ("Thursday") Then
ItIsFriday = False
If ItIsFriday = False Then
Me.Txt_Header2.Visible = False
Me.Txt_bx_DateHeader.Visible = True
If FormStrFri = ("Saturday") Then
ItIsFriday = False
If ItIsFriday = False Then
Me.Txt_Header2.Visible = False
Me.Txt_bx_DateHeader.Visible = True
If FormStrFri = ("Sunday") Then
ItIsFriday = False
If ItIsFriday = False Then
Me.Txt_Header2.Visible = False
Me.Txt_bx_DateHeader.Visible = True
Else: ItIsFriday = False
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

Copyright 1998-2015 Ziff Davis, LLC (Toolbox.com). All rights reserved. All product names are trademarks of their respective companies. Toolbox.com is not
affiliated with or endorsed by any company listed at this site.