Results 1 to 19 of 19

Thread: [RESOLVED] EASY quick question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Resolved [RESOLVED] EASY quick question

    I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not working
    VB Code:
    1. Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: EASY quick question

    this works for my label but how do I get it to work for the txtbox
    VB Code:
    1. Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")

  3. #3
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: EASY quick question

    What error do you get (or what is the result of calling the code) ?
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: EASY quick question

    Quote Originally Posted by vonoventwin
    I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not working
    VB Code:
    1. Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
    This code works just fine for me. The result that I get is: Friday, Sep 9 2005, 07:19 AM

  5. #5
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: EASY quick question

    I suspect it's a scope thing going on with the 'Me' bit
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: EASY quick question

    Quote Originally Posted by yrwyddfa
    I suspect it's a scope thing going on with the 'Me' bit
    Ahhhh...me thinks you may have hit on something as I didn't use the Me keyword.

    vonoventwin: Why are you using Me and how is it not working.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: EASY quick question

    "Me!lblClock.Caption" is a Access Forms format. Are you using an Access form or VB 6.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: EASY quick question

    Quote Originally Posted by RobDog888
    "Me!lblClock.Caption" is a Access Forms format. Are you using an Access form or VB 6.
    As far as I know I don't even have VB on my computer, just whatever is in with Access. Is that VB?

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: EASY quick question

    Oh, ok. Then your using Access VBA (Visual Basic for Applications).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: EASY quick question

    VBA is also located in Word, Excel, FrontPage, Outlook, and PowerPoint.

  11. #11
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: EASY quick question

    Quote Originally Posted by vonoventwin
    I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not working
    VB Code:
    1. Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")

    I have also found that using the ".Text" Property when assigning data to a text box causes problem. This should work for you:

    VB Code:
    1. Me.txtDate = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")

    Also if you have multiple text boxes and you want to refer to them in a kind of control array you can do this:

    VB Code:
    1. Option Compare Database
    2.  
    3. Private Sub Command1_Click()
    4. Dim a As Long
    5.  
    6.     For a = 0 To 6
    7.         Me("Text" & a) = "Text Box # " & a
    8.     Next a
    9. End Sub

    This code assumes that you have seven (7) text boxes Named Text0 through Text6.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: EASY quick question

    Turns out to be a VBA question. Moved to Office Development.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: EASY quick question

    Doesnt work for me Mark...

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: EASY quick question

    Quote Originally Posted by vonoventwin
    Doesnt work for me Mark...
    What, exactly, happens when you run that code? Do you get anything? Do you get an error? If so, what is the error?

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: EASY quick question

    forms txtDate box show #Error. Now what I have even tried is to create the label (Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM") which works fine and then give the txtDate box the =[lblClock].[Caption] . This used to work but I'm not sure why it doesn't anymore.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: EASY quick question

    Well I just figured it out, I have the txtDate format as a date/time, when I change it to Text it works fine. Good enough for me!

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] EASY quick question

    The .Text and .Value properties are usually interchangeable but can sometimes contain different values. Is this a bound textbox?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: [RESOLVED] EASY quick question

    If you are getting #error it is because there is an error in the data tab of the properties form (probably a wrong formula).

    Marks code would work, but it is VBA code and has to be called in the On_Load event of the form or via a click of a button.

    Your error would either be in the data source or you need to put ' now() ' (without single quotes) into the properties>data tab>default value.

    Post up what you have?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: [RESOLVED] EASY quick question

    I had to make it Me.txtDate = Now, the Value for the the feild in the table is Date/Time that's why!

Posting Permissions

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



Click Here to Expand Forum to Full Width