opening recordsets in forms coding

G

Guest

I wish to compare two tables and based on the existance of data I want to
insert data into table 2.. I am using the following code for this. but It
says type mismatch near set rs1 = "select ..."

Pls help

Private Sub CmdImpDB_Click()
Dim SQL As String
Dim cn As Connection
Dim rs As Recordset
Dim rs1 As Recordset

Set cn = CurrentDb.Connection
Set rs1 = "select * from tbl_wc_wcands_kpwcmatch"

Do While rs1.EOF = False
SQL = rs1!REC_ISN
Set rs = "select * from kpwcmaster,tbl_wc_wcands_kpwcmatch where
kpwcmaster.rec_isn = '" & SQL & "'"
If rs.EOF Then
DoCmd.RunSQL "insert into kpwcmaster select * from
tbl_wc_wcands_kpwcmatch where rec_isn='" & SQL & "'"

End If
rs1.MoveNext
Loop


End Sub

Madhuri
 
G

Guest

Try this, see if that helps

Private Sub CmdImpDB_Click()
Dim SQL As String
Dim MyDB As Database
Dim rs As Recordset
Dim rs1 As Recordset

Set MyDB = CodeDb()
Set rs1 = MyDB.openRecordset ("select * from tbl_wc_wcands_kpwcmatch")

While not rs1.EOF
SQL = rs1!REC_ISN
Set rs = MyDB.openRecordset ("select * from kpwcmaster,
tbl_wc_wcands_kpwcmatch where kpwcmaster.rec_isn = '" & SQL & "'")
If rs.EOF Then
DoCmd.RunSQL "insert into kpwcmaster select * from
tbl_wc_wcands_kpwcmatch where rec_isn='" & SQL & "'"

End If
rs1.MoveNext
Wend


End Sub
 
G

Guest

Thanks Ofer

I dont know what went wrong with me today. I should have defined recordset
with respect to the connection. My problem is that I am a vb programmer and
my current project wants me to work with msaccess as a front end which I get
upset about. But thats ok...

Could you please help me by referring any links which could offer me help on
MS Access as front end and SQL Server as backend ?

And also let me know whether the forms I am developing in access could be
used both for msaccess and SQL server as backend.

Thanks
Madhuri
 
G

Guest

You can use google to serch for the subject "Access with Sql Server"

And yes, access could be used both for msaccess and SQL server as backend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to open recordset 1
On Change Update Subform 1
Selecting record from unbound box 2
can't find strSQL 1
Append Recordset 2
trouble printing variavel 1
Recordset Help 10
stuck in a loop 5

Top