How to run sql residing in the column..

vsap

vsap
Local time
Yesterday, 23:44
Joined
May 27, 2005
Messages
29
Hello guys,
Its a tricky question,hope to get answer ,well my question is ,i have a
table name : refer_lgl_mgr it has
col name : qrynm which holds my query
select atab,btab from s_prod
where atab like 'Asr%'
how can I execute the qrynm column.
if it can be executed I need to insert the value of atab,btab
into table call refer_cv with same col atab and btab.

One thing is that this should happen when user presses the button.the code is shown below which i tried:
----
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click

'Dim conn As New ADODB.Connection
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Dim Rqry As String


conn.Open "conn", "meuser", "jul"

' Fetch qry.

Set rs = conn.Execute("SELECT QRYNM FROM REFER_LGL_MGR")

Dim strsql
If Not rs.EOF Then
rs.MoveFirst
Do While Not rs.EOF
Rqry = rs.Fields(0).Value

MsgBox Rqry

strsql = "Insert into refer_cv " & Rqry
conn.Execute strsql
rs.MoveNext
Loop
End If
rs.Close


Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub

------
So I get just qry in msgbox ,but not result set so what i am missing let me know,if anyone can help me.

Hope to get answer asap.

Thanks
vsap
 
vsap,

strsql = "Insert into refer_cv '" & Rqry & "'"

It should work, but you could also do:

DoCmd.RunSQL strsql

Wayne
 
Wayne,
Thanks for reply,but it din't work,I want to know how I can execute the sql code residing in the field of given table.
While doing this it gives me error stating,C:\..\..\ .mdb not found.

Thanks
vsap
 
vsap,

Well ...

Rqry = rs.Fields(0).Value

Rqry seems to come from your table. And I take it that it looked OK
in the MessageBox.

Could you post what was displayed in the MessageBox?

Can't make it work if I don't know what it is.

Wayne
 

Users who are viewing this thread

Back
Top Bottom