Hi Arun,
Here is something you can try that is a little bit simple - for
starters. Then you can use the values contained in textboxes to get
table/field names dynamically.
----------------------------------------------
Private Sub Command3_Click()
Dim qd As DAO.QueryDef, db As DAO.Database
Set db = CurrentDb
For Each qd In db.QueryDefs
If qd.Name = "test1" Then
db.QueryDefs.Delete qd.Name
Exit For
End If
Next
Set qd = db.CreateQueryDef("test1")
qd.SQL = "select fname, lname, num from tbl1"
DoCmd.OpenQuery "test1"
End Sub
--------------------------------------------
this example is using a tbl called "tbl1" which contains the fields
fname (text), lName (text) num (number). To implement dynamically - you
can do this
------------------------------------------------
Private Sub Command3_Click()
Dim qd As DAO.QueryDef, db As DAO.Database
Set db = CurrentDb
For Each qd In db.QueryDefs
If qd.Name = "test1" Then
db.QueryDefs.Delete qd.Name
Exit For
End If
Next
Set qd = db.CreateQueryDef("test1")
qd.SQL = "select " & txtFname & ", " & txtLname & ", " & txtNum & " from
" & txtTblName
DoCmd.OpenQuery "test1"
End Sub
----------------------------------------------------
Rich
*** Sent via Developersdex
http://www.developersdex.com ***