Solved

Looping thru records as a lookup

Posted on 2014-02-14
3
205 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

776 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