Results 1 to 2 of 2
  1. #1
    smitstev is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    4

    Automatically Writing SQL From A Table

    Hello,



    I am creating a database that needs to exclude many differnt factors (which will also need to be edited and changed on a regular basis). Is there anyway I can have a table which contains a description of the exception, and the SQL statement... From here I would like for access to automatcially generate the SQL statements based upon the list of the exceptions. This would leave me with a query that has left me with the exceptions.

    Is this possible?

    Any help would be greatly apprciated...

  2. #2
    Patrick.Grant01 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    30
    You could do something along these lines. Use an ADODB recordset to read the table and create as a string. Then use the SQL string to create another recordset.

    Sample code below:
    Dim rstCheckInvestment As ADODB.Recordset


    Set rstCheckInvestment = New ADODB.Recordset
    Set rstCheckInvestment.ActiveConnection = CurrentProject.Connection
    rstCheckInvestment.CursorType = adOpenKeyset
    rstCheckInvestment.LockType = adLockOptimistic
    strSQL = "SELECT * FROM tblInvestment Where SharescopeId =" & ExternalKey
    rstCheckInvestment.Source = strSQL
    rstCheckInvestment.Open

    Loop through the recordset using Do While not rst.Eof and rst.MoveNext and rst.Close. etc.

    I think ADO is documented in the VBA help - but its hard to read...

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

Similar Threads

  1. Help writing multiple queries
    By wz72n01 in forum Queries
    Replies: 1
    Last Post: 05-24-2009, 12:30 PM
  2. Replies: 9
    Last Post: 04-28-2009, 05:42 PM
  3. linking forms by ID - automatically add ID
    By jlcaviglia-harris in forum Forms
    Replies: 0
    Last Post: 04-17-2009, 03:51 PM
  4. I need help writing a query statement
    By dking in forum Queries
    Replies: 1
    Last Post: 02-25-2009, 09:43 AM
  5. Force writing from the right in a field?
    By Looping in forum Forms
    Replies: 0
    Last Post: 01-23-2006, 03:03 AM

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