Consulting

Results 1 to 15 of 15

Thread: Solved: Inserting Day of the week on a userform TextBox

  1. #1
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location

    Solved: Inserting Day of the week on a userform TextBox

    Hi Captains

    Two Small problems tonite

    1) On a userform if I insert a labelBox is there a setting in the Properties of that label... so that the end user can enter text into it ? say a box of tomatoes


    2)I have Tried to insert the day of the week in a user form hmm I can get the Now() statement to work but not the day

    my code

    [VBA]Private Sub CommandButton1_Click()
    Hide
    OverHeads.Show
    End Sub
    Private Sub Label45_Click()
    End Sub
    Private Sub UserForm_Activate()
    End Sub
    Private Sub UserForm_Initialize()
    TextBox1 = Now()
    TextBox3 = Date
    TextBox4 = MyWeekdayDay

    End Sub
    Private Sub TextBox3_Change()
    Dim MyDate
    MyDate = Date ' MyDate contains the current system date.

    End Sub
    Private Sub TextBox4_Change()
    Dim MyDate, MyWeekDay
    MyDate = #8/31/2007# ' Assign a date.
    MyWeekDay = Weekday(MyDate) ' MyWeekDay contains 4 because
    ' MyDate represents a Wednesday.
    End Sub
    Private Sub TextBox17_AfterUpdate()
    TextBox17 = Format(TextBox17, "#,##0.00")
    If TextBox17.Text <> "" Then

    End If
    TextBox26.Text = Format(SumExpensesCash, "#,##0.00")
    TextBox49.Text = Format(TextBox26.Text, "#,##0.00")
    End Sub[/VBA]

    Picture

    Thanks guys and ladies

    Darren
    South Africa
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    1 No, a user can't put information in a label control.

    2 Try taking a look at the Format function.

    Perhaps something like this?
    [vba]
    TextBox4 = Format(MyDate, "dddd")
    [/vba]

    Though I do think you might have some declaration/scope issues to sort.

  3. #3
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    Hi Norie

    Thanks for the advice will change them to text boxes and set the tab index one to the other. I will try the day function

    Kindest regards

    Darren
    South Africa
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  4. #4
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    Hi Norie

    Tried what you suggested but no change in textBox4 it stays blank ?

    [VBA]Private Sub TextBox4_AfterUpdate()
    TextBox4 = Format(MyDate, "dddd")
    End Sub
    Private Sub UserForm_Initialize()
    TextBox1 = Now()
    TextBox3 = Date
    TextBox4 = Format(MyDate, "dddd")
    End Sub
    Private Sub TextBox3_Change()
    Dim MyDate
    MyDate = Date ' MyDate contains the current system date.

    End Sub
    Private Sub TextBox4_Change()
    TextBox4 = Format(MyDate, "dddd")
    End Sub[/VBA]

    Thanks


    Darren
    South Africa
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Darren

    Did you see my comment regarding declaration/scope?

    You've declared MyDate within the Change event of TextBox3.

    No other subs will be able to access it. ie it's not in scope

  6. #6
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Your mydate variable should be declared publicly. Not inside any one module.

    [VBA]Option Explicit
    Public MyDate As Date
    Private Sub UserForm_Initialize()
    TextBox1 = Now()
    TextBox3 = Date
    TextBox4 = Format(MyDate, "dddd")
    End Sub

    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    As Norie has already pointed out. Sorry Norie I should have refreshed before posting.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    Hi Norrie & Lucas

    Thanks for the info still learning the queens english and the big words too.

    I will get there i know it!!!

    Lucas i pasted the code into the sheet and it works but it shows a Saturday should i add + 1 to the code

    current code is as follows

    [VBA]Option Explicit
    Public MyDate As Date
    Private Sub UserForm_Initialize()
    TextBox1 = Now()
    TextBox3 = Date
    TextBox4 = Format(MyDate, "dddd")
    End Sub
    Private Sub CommandButton1_Click()
    Hide
    BasicTerms.Show
    End Sub

    Private Sub TextBox4_AfterUpdate()
    TextBox4 = Format(MyDate, "dddd")
    End Sub

    Private Sub TextBox3_Change()
    Dim MyDate
    MyDate = Date ' MyDate contains the current system date.

    End Sub
    Private Sub TextBox4_Change()
    TextBox4 = Format(MyDate, "dddd")
    End Sub[/VBA]

    You guys are champions

    Darren
    South Africa
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by Darren
    On a userform if I insert a labelBox is there a setting in the Properties of that label... so that the end user can enter text into it ? say a box of tomatoes
    You can remove the TextBox appearance. Make BackColor transparent and SpecialEffects to Etched, for example.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    the current snapshot
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  11. #11
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You probably need to set the date to get it to read the right day
    [VBA]Private Sub UserForm_Initialize()
    MyDate = Date
    TextBox1 = Now()
    TextBox3 = Date
    TextBox4 = Format(MyDate, "dddd")
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    Hi Guys

    Thank you it works like a charm Norie, Lucas & Malcolm

    If i only had 1 percent of your knowledge !!!

    Thanks
    Darren
    South Africa

    The code that works

    [VBA]Option Explicit
    Public MyDate As Date
    Private Sub UserForm_Initialize()
    MyDate = Date
    TextBox1 = Now()
    TextBox3 = Date
    TextBox4 = Format(MyDate, "dddd")
    End Sub
    Private Sub CommandButton1_Click()
    Hide
    BasicTerms.Show
    End Sub

    Private Sub TextBox4_AfterUpdate()
    TextBox4 = Format(MyDate, "dddd")
    End Sub

    Private Sub TextBox3_Change()
    Dim MyDate
    MyDate = Date ' MyDate contains the current system date.

    End Sub
    Private Sub TextBox4_Change()
    TextBox4 = Format(MyDate, "dddd")
    End Sub[/VBA]
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  13. #13
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    Hi Malcolm

    Works well as instructed, but hat to set Backstyle to transperent not color and it is super thanks Malc


    Darren
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

  14. #14
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Darren,
    Nothing really going on here.....? I don't think you need it. I would think you would want it to read like the other texboxes with it's own formatting.
    [VBA]Private Sub TextBox3_Change()
    Dim MyDate
    MyDate = Date ' MyDate contains the current system date.

    End Sub
    [/VBA]
    MyDate is declared publicly so no need to dim it here. Then you set it but never use it.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  15. #15
    VBAX Regular Darren's Avatar
    Joined
    Feb 2005
    Posts
    98
    Location
    Hi Lucas

    Thanks for the tidy up. Champ

    Darren
    South Africa
    Live by Ghandi and learn 1st by "Vbaexpress.com and then by Google" !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •