Results 1 to 4 of 4

Thread: create querry at run-time

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    104
    If you want to create a QueryDef object at runtime here is an example from DAO help:

    Code:
    Sub CreateQueryDefX()
    
    	Dim dbsNorthwind As Database
    	Dim qdfTemp As QueryDef
    	Dim qdfNew As QueryDef
    
    	Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    
    	With dbsNorthwind
    		' Create temporary QueryDef.
    		Set qdfTemp = .CreateQueryDef("", _
    			"SELECT * FROM Employees")
    		' Open Recordset and print report.
    		GetrstTemp qdfTemp
    		' Create permanent QueryDef.
    		Set qdfNew = .CreateQueryDef("NewQueryDef", _
    			"SELECT * FROM Categories")
    
    ' Open Recordset and print report.
    		GetrstTemp qdfNew
    		' Delete new QueryDef because this is a demonstration.
    		.QueryDefs.Delete qdfNew.Name
    		.Close
    	End With
    
    End Sub
    
    Function GetrstTemp(qdfTemp As QueryDef)
    
    	Dim rstTemp As Recordset
    
    	With qdfTemp
    		Debug.Print .Name
    		Debug.Print "    " & .SQL
    		' Open Recordset from QueryDef.
    		Set rstTemp = .OpenRecordset(dbOpenSnapshot)
    
    		With rstTemp
    			' Populate Recordset and print number of records.
    
    .MoveLast
    			Debug.Print "    Number of records = " & _
    				.RecordCount
    			Debug.Print
    			.Close
    		End With
    
    	End With
    
    End Function

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Sounded to me like he wanted to have one (actually 4) queries that serviced any table he creates. Like:



    Function BuildSQL(tablename As String) as string

    dim sSQL as string

    sSQL= "select * from " & trim(tablename) & " where condition"



    End Function


  3. #3
    New Member
    Join Date
    Jul 2000
    Location
    Posts
    6
    Exactlly right, JHausmann.
    I could read the data back out, do the calc, and save the results to their own fields, although the operations are being done on 300+ point waveforms. I won't have a chance to try again till monday. Going back to the querry, I was able to sorta create querries using the db.CreateQueryDef method but they all end up in their own table. Is there a way to group them?

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Not sure on what you want to group. if the structure of your results will always be the same (ie; data returned for any group of queries is of compatible type), you could union them into a temp table

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width