Solved

Looping thru records as a lookup

Posted on 2014-02-14
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 51

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

615 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