Date to day of week (1 Viewer)

BobNTN

Registered User.
Local time
Today, 17:29
Joined
Jan 23, 2008
Messages
308
I have a field ldate (lesson date). Next to that, I have a field ldow (lesson day of week). I am trying to return the day of week in that field based on the ldate then save both to the table.
ex. I input 01/14/2012 in the ldate field I want it to return Sat in the ldow field.
Is that possible ?
I did search but couldn't / didn't find anything specific to converting this way.
 

Mr. B

"Doctor Access"
Local time
Today, 16:29
Joined
May 20, 2009
Messages
1,932
To display the name of the day represented by the date entered, use the following in the Control Source of the control where you want to see the name of the day of the week:

Code:
=Format([NameOfControlWithDate],"dddd")

Change the "NameOfControlWithDate" to be the actual name of the control that will have the date value.
 

BobNTN

Registered User.
Local time
Today, 17:29
Joined
Jan 23, 2008
Messages
308
Thanks Mr. B.
However, it does not save the result to the table.
What am I missing ?
 

missinglinq

AWF VIP
Local time
Today, 17:29
Joined
Jun 20, 2003
Messages
6,423
You are calculating the 'day of the week' here, and calculated values should not be saved to the underlying Table, they should simply be re-calculated as needed.

Having advised you of best practices, if you insist on doing this, you need to move your expression from the Control Source (which will have to be set to the Field in the underlying Table where you want the day stored) and move it to the AfterUpdate event of the ldate Textbox.
Code:
Private Sub ldate_AfterUpdate()
 If Nz(Me.ldate,"") <> "" Then
  Me.ldow = Format(Me.ldate,"dddd")
 End If
End Sub
Linq ;0)>
 

BobNTN

Registered User.
Local time
Today, 17:29
Joined
Jan 23, 2008
Messages
308
You are calculating the 'day of the week' here, and calculated values should not be saved to the underlying Table, they should simply be re-calculated as needed.
Need a report that shows the actual day names as well as the dates.

Having advised you of best practices, if you insist on doing this, you need to move your expression from the Control Source (which will have to be set to the Field in the underlying Table where you want the day stored) and move it to the AfterUpdate event of the ldate Textbox.
Code:
Private Sub ldate_AfterUpdate()
 If Nz(Me.ldate,"") <> "" Then
  Me.ldow = Format(Me.ldate,"dddd")
 End If
End Sub
Linq ;0)>

Tried this, still doesn't save the day name to the table.
I suppose the easiest thing to do would be have them input the day name (Mon, Tue, etc) as they go.


I appreciate the help.
 

missinglinq

AWF VIP
Local time
Today, 17:29
Joined
Jun 20, 2003
Messages
6,423
...still doesn't save the day name to the table.
You cannot simply use the code. As I said, you also have to set the Control Source of the ldow Textbxox to a Field in your Table.

In Form Design View
  • Right Click on the ldow Textbox
  • Click on the Data Tab
  • Use the Drop Down Arrow beside the Control Source Property box to select the Field you want the day of the week saved in
Linq ;0)>
 

BobNTN

Registered User.
Local time
Today, 17:29
Joined
Jan 23, 2008
Messages
308
You cannot simply use the code. As I said, you also have to set the Control Source of the ldow Textbxox to a Field in your Table.
Sorry, should have stated that I did.
I removed the code and replaced it with the table field ldow
.
Inserted the code in the After_update of ldate.
Checked the type of the ldow field in the table, set to text.
Doesn't give any errors but doesn't save to ldow.



In Form Design View
  • Right Click on the ldow Textbox
  • Click on the Data Tab
  • Use the Drop Down Arrow beside the Control Source Property box to select the Field you want the day of the week saved in
Linq ;0)>
Like I said, probably would be easier to just have them input the day name as they input. Just thought it would be cute to auto do it.
Thanks
 

Mr. B

"Doctor Access"
Local time
Today, 16:29
Joined
May 20, 2009
Messages
1,932
If you are wanting to actually have the string value for the selected date written to the Idow field, place the following code in the After Update event of the text box where the date is entered.

Code:
Dim bytWeekDay As Byte
bytWeekDay = Format(Me.NameOfDateTextBox, "w")
Select Case bytWeekDay
    Case 1  'Sunday
        Me.NameOf_IdowTextBox = "Sunday"
    Case 2  'Monday]
        Me.NameOf_IdowTextBox= "Monday"
    Case 3  'Monday]
        Me.NameOf_IdowTextBox= "Tuesday"
    Case 4  'Monday]
        Me.NameOf_IdowTextBox= "Wednesday"
    Case 5  'Monday]
        Me.NameOf_IdowTextBox= "Thrusday"
    Case 6  'Monday]
        Me.NameOf_IdowTextBox= "Friday"
    Case 7  'Monday]
        Me.NameOf_IdowTextBox= "Saturday"
End Select

This will actually write the string value to the text box. Using the Format function only formats the date to show the name of the day of the week.
 

missinglinq

AWF VIP
Local time
Today, 17:29
Joined
Jun 20, 2003
Messages
6,423
..This will actually write the string value to the text box. Using the Format function only formats the date to show the name of the day of the week.
Afraid that's simply not true, Mr. B! The code I gave, using Format(), will write the day of the week to the Table, assuming that the Textbox is Bound to a Field in the Table. And it does so in 3 lines instead of 18 lines!
 
Last edited:

BobNTN

Registered User.
Local time
Today, 17:29
Joined
Jan 23, 2008
Messages
308
Sorry ling for not getting back sooner.
I had typed in the field name into the Control Source. Apparently it never recognized it for whatever reason nor did it give any error.
Finally picked it from the list and it works.

Thanks loads for the help and patience.
 

Users who are viewing this thread

Top Bottom