Results 1 to 9 of 9
  1. #1
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370

    Question Assigning textbox value through vb

    Hello all,

    I'm having trouble assigning a textbox a value that is calculated in vb.



    I have little experience in vb, so I'm probably missing something fairly simple.

    Code:
    Private Sub Form1_Load()
    
    Dim Week As Date
    
    
    Week = DCount("Field1", "Table1", "[Field1] Between #1/1/2014# And #1/8/2014#")
    Me.Text2.Value = Week
    
    
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, I would declare the variable as Integer, since it's a count that you're putting in it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Ok, thanks.

    I'm still getting nothing in my textbox.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Week might be a reserved word, so try changing that too. Type this in the Immediate window and see what you get:

    ?DCount("Field1", "Table1", "[Field1] Between #1/1/2014# And #1/8/2014#")

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    I get the correct number when I use that in the immediate window.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The event looks odd. Put a message box in there and see if it's even running the code. Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Sure, here it is:

    I'm not sure how to put in a message box to see if it's running the code.


    CountingDates.zip

  8. #8
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Got it Paul, the event wasn't even being recognized in the properties of the form.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sounded like it was something like that. Glad you got it sorted.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 04-30-2015, 01:50 AM
  2. Replies: 3
    Last Post: 07-25-2013, 05:19 PM
  3. Replies: 2
    Last Post: 04-20-2013, 03:37 AM
  4. Replies: 1
    Last Post: 02-29-2012, 04:46 PM
  5. Ranking and assigning a Value
    By loopyl00 in forum Access
    Replies: 0
    Last Post: 01-11-2011, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums