Results 1 to 4 of 4
  1. #1
    elementalnature is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    3

    Loop Counter


    Hello! I seem to be having an issue where I have a SQL/VBA script that calls dates from a table called tblForm91Entries and references a few other tables named tblPersonnel and tblform91MetaEntries. I'm using the below script to call this information on a report, that is based on a member inputting data on a form.
    Code:
    Option Compare Database
     
    Function getItemDate(personnelID As Integer, Position As String, EntryTimeframe As String, EntryTimeframe1 As String)
        Dim mySQL, dateType As String, myDB As DAO.Database, myRec As DAO.Recordset
        'position = AEP SSO, LADO SSO, Evaluator, MCMDR, Instructor, AEP PSO, LADO SVO, AEP SVO
        'date Types = MRT , MRT, ERT, MRT, IRT, MRT, MRT, MRT
       
        If Position = "Evaluator" Then
            dateType = "ERT"
        ElseIf Position = "Instructor" Then
            dateType = "IRT"
        Else
            dateType = "MRT"
        End If
       
        mySQL = "SELECT tblPersonnel.LastName, tblPersonnel.PersonnelID, tblForm91Entries.ItemDate, tblForm91MetaEntries.EntryType, tblForm91MetaEntries.EntryTimeframe " + _
        "FROM tblForm91MetaEntries INNER JOIN (tblPersonnel INNER JOIN tblForm91Entries ON tblPersonnel.PersonnelID = tblForm91Entries.PersonnelID) ON tblForm91MetaEntries.ID = tblForm91Entries.MetaEntry " + _
        "WHERE (((tblPersonnel.PersonnelID)=" + Nz(Str(personnelID)) + ") AND ((tblForm91MetaEntries.EntryType)='" + dateType + "') AND ((tblForm91MetaEntries.EntryTimeframe)='" + Nz(EntryTimeframe) + "')); "
       
        Set myDB = CurrentDb
        Set myRec = myDB.OpenRecordset(mySQL)
       
        Do While Not myRec.EOF
            getItemDate = Nz(myRec![ItemDate])
            myRec.MoveNext
        Loop
        If Nz(getItemDate) = "" Then
            getItemDate = ""
        End If
    End Function
    The two dialog boxes are called via
    Code:
    Function getItemDate(personnelID As Integer, Position As String, EntryTimeframe As String, EntryTimeframe1 As String)
    (note that the blue text are the expressions that act as dialog boxes.)

    So within the tblform91MetaEntries are the values that I want to input into the dialog boxes, usually it is something similar to a month year such as August 2012 or a quarter value such as 2nd Quarter 2012. For my purpose I need two dialog boxes that allow me to enter both values (August 2012 and 2nd Quarter 2012) however, the VBscript only uses the first inputted value. For example if August 2012 is entered in the first box, it completely disregards 2nd Quarter 2012 and visa versa. I was told to loop it so it asks the questions until it runs out of records to loop to. Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Use debug techniques, refer to link at bottom of my post. Set a breakpoint, follow the code as it executes one line at a time. Does it do what you expect?

    Have you compiled the code? Does the procedure run?

    You probably need the If structure within the loop. Consider:
    Code:
    Do While Not myRec.EOF
       If Nz(getItemDate) <> "" Then
            getItemDate = myRec![ItemDate]
       End If
       myRec.MoveNext
    Loop
    Is it possible the sql will have more than one record that will meet the If condition? What is it you are trying to accomplish? You might be making this harder than necessary. Could the sql be designed with criteria to return only one record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    elementalnature is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    3
    The code compiles, runs, returns the correct records for the first value input. The second value however is completely disregarded. So if I add an if statement, that might help?

  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,641
    You say the second value is disregarded, but I don't see that you ever use it in the code. Am I missing something?
    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. Help with incrementing a counter
    By Ben M in forum Database Design
    Replies: 4
    Last Post: 05-22-2012, 06:46 AM
  2. Counter
    By Skroof in forum Access
    Replies: 3
    Last Post: 05-14-2012, 08:25 AM
  3. Database Counter
    By Kapelluschsa in forum Access
    Replies: 5
    Last Post: 08-10-2011, 02:41 PM
  4. Need counter to print
    By miziri in forum Access
    Replies: 1
    Last Post: 05-11-2011, 02:07 AM
  5. lap Counter
    By challenger in forum Access
    Replies: 4
    Last Post: 07-06-2010, 02:20 PM

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