Solved

Looping thru records as a lookup

Posted on 2014-02-14
3
202 Views
Last Modified: 2014-02-20
I need help to create the best option for check to see if the values in a table (4 fields) = True, if they do then run 2 queries.

the

SELECT tblCurrent.Year, tblCurrent.FreezeQ1, tblCurrent.FreezeQ2, tblCurrent.FreezeQ3, tblCurrent.FreezeQ4
FROM tblCurrent;

Since each field (FreezeQ & ((numeric Value)  - ie. FreezeQ1 or FreezeQ2, etc.

I would like to use a variable to pass the numeric value of the field name.

Also loop thru each of these fields to determine if they = True.

Below is my many attempts, feel free to choose the best option to simplify the task.

   Dim strsql As String
   Dim nCt As Integer
   Dim nQtr As String
   Dim rs As DAO.Recordset
   
   Set rs = curDB.OpenRecordset("Select * from tblcurrent")
    for each (i)
    If rs.Fields("FreezeQ" & (i)) Then
    
    End If
    Do Until X = nQtr
        For X = i To nQtr
        For Each X In nQtr
            curDB.Execute ("DELETE *" & _
                            " FROM tblSummary" & _
                            " WHERE Quarter = " & nQtr & ")")
            curDB.Execute ("INSERT INTO tblSummary" & _
                            "Select *" & _
                            " FROM tblSummaryQuartersFrozen" & _
                            " WHERE Quarter = " & nQtr & ")")

        Next
     MoveNext
    Loop

Open in new window

0
Comment
Question by:Karen Schaefer
3 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39860799
You would do something like this:
  For i = 1 to 4
    If rs.Fields("FreezeQ" & i) Then
        ...
    Next i
    

Open in new window

Ron
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39861072
I guess you are after something like:
   Dim strsql As String
   Dim nCt As Integer
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   
   Set db = CurrentDb
   Set rs = db.OpenRecordset("Select * from tblcurrent")

   While rs.EOF = False
      For nCt = 1 To 4
          If rs.Fields("FreezeQ" & CStr(i)).Value = True Then
               db.Execute ("DELETE *" & _
                               " FROM tblSummary" & _
                               " WHERE Quarter = " & nQt & ")")
               db.Execute ("INSERT INTO tblSummary" & _
                               "Select *" & _
                               " FROM tblSummaryQuartersFrozen" & _
                               " WHERE Quarter = " & nQt & ")")
          End If
      Next
      rs.MoveNext
   Wend

Open in new window

/gustav
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39875326
thanks that did the trick.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now