Results 1 to 5 of 5
  1. #1
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27

    DCount Works, But Not on First Load

    Hi. I have been making a language learning app (basically for myself, really). It's almost finished. I have a "STATS - Rework" form that is pulling information from 4 different, unrelated tables. I stated by using the expression builder, but discovered that it doesn't seem to like more than one unrelated table, so I've resorted to DAO coding instead (and, then discovered that it's MUCH faster, lol). But I have a problem where in this STATS form, because it's basically counting the number of records in many ways, I've used a lot of Dcounts to get that information.

    But the curious thing is that the DCount commands are not finding records on the first load. So if I open my form, it finds 0 records, but if I change it to design view, then back to form view, the DCount then works, pulling the correct number of records. So I know that my DCount coding is correct because it DOES work, but not the first time the form is loaded.



    The code is in Form_Load. I have attached my application for you to see, in case you need more information than just the code. Please note that I am a beginner in VBA, and have recently (the last month or so) learned it to write this application, so my knowledge of programming is limited to what you can see in the app (and learning gleaned from YouTube and various sights to find out how to do stuff). I have Googled extensively trying to find someone else with this problem and found nothing! Should I try moving to another event? Form_Load is usually okay. Is Long the wrong variable? I tried several and Long was the one I found to work. I also tried moving the rst.RecordCount to after the DCounts in case it held it up, but that didn't work either. I also shortened my query to see if that helped. I'm at a loss. Thanks in advance!! :-)MyCurrentLearningWords.zip


    Private Sub Form_Load()
    Dim Listening As Long
    Dim Reading As Long
    Dim Meaning As Long
    Dim Ready As Long


    Set db = CurrentDb
    ' Set rst = db.OpenRecordset("SELECT FutureWordList.ID, FutureWordList.ListeningSuccess, FutureWordList.NumSccssList, FutureWordList.NumSccssRec FROM FutureWordList")
    Set rst = db.OpenRecordset("SELECT FutureWordList.ID FROM FutureWordList")

    rst.MoveLast
    Me.TxtTotalFutureWords = rst.RecordCount

    Listening = DCount("TxtListening", "FutureWordList", "ListeningSuccess < 20")
    Reading = DCount("TxtReading", "FutureWordList", "NumSccssList < 10 and ListeningSuccess > 20")
    Meaning = DCount("TxtMeaning", "FutureWordList", "NumSccssRec < 10 and NumSccssList > 10 and ListeningSuccess > 20")
    Ready = DCount("TxtReady", "FutureWordList", "NumSccssRec > 10 and NumSccssList > 10 and ListeningSuccess > 20")
    Me.TxtListening = Listening
    Me.TxtReading = Reading
    Me.TxtMeaning = Meaning
    Me.TxtReady = Ready


    rst.Close
    Set rst = Nothing
    Set db = Nothing

    Dim zero As Long
    Dim one As Long
    Dim two As Long
    Dim three As Long
    Dim four As Long


    Set db = CurrentDb
    Set rst = db.OpenRecordset("SELECT Acquired.ID, Acquired.MonthlyCount FROM Acquired")

    rst.MoveLast
    Me.TxtBTotalAcquired = rst.RecordCount

    zero = DCount("TxtBAq0", "Acquired", "MonthlyCount = 0")
    Me.TxtBAq0 = zero
    one = DCount("TxtBAq1", "Acquired", "MonthlyCount = 1")
    Me.TxtBAq1 = one
    two = DCount("TxtBAq2", "Acquired", "MonthlyCount = 2")
    Me.TxtBAq2 = two
    three = DCount("TxtBAq3", "Acquired", "MonthlyCount = 3")
    Me.TxtBAq3 = three
    four = DCount("TxtBAq4", "Acquired", "MonthlyCount = 4")
    Me.TxtBAq4 = four


    rst.Close
    Set rst = Nothing
    Set db = Nothing


    Set db = CurrentDb
    Set rst = db.OpenRecordset("SELECT Archive.ID FROM Archive")

    ' rst.MoveLast (this won't work until there is a record in the table)
    ' Me.TxtBArchived = rst.RecordCount

    rst.Close
    Set rst = Nothing
    Set db = Nothing

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    DCount("*",....)

  3. #3
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    Ah! Thank you!! Obviously I followed someone's instructions too literally!

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,861
    Your learning 2 languages, Korean and VBA!

  5. #5
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    Haha! Yes I am! And VBA is much easier, lol!

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

Similar Threads

  1. Replies: 37
    Last Post: 10-21-2019, 12:29 PM
  2. On Load VBA
    By sparker75 in forum Programming
    Replies: 8
    Last Post: 08-28-2018, 02:36 PM
  3. Replies: 1
    Last Post: 06-21-2015, 07:58 AM
  4. Replies: 4
    Last Post: 06-24-2014, 10:49 AM
  5. Replies: 12
    Last Post: 03-27-2014, 04:49 AM

Tags for this Thread

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