Question : MS Access 2007 Button Click Insert/Append Data Into Table

I am using following code to insert data from one table to an other table after checking data existance. it is showing error, which is as follows: please help to fix.
Error:
Compile Error:
Argument not optional

Line:
Set rsInsert = CurrentDb.OpenRecordset

Code:
Private Sub Command27_Click()
If ID.Value = "" Then
        MsgBox ("Please check Trans #")
        Exit Sub
    ElseIf ID.Value <> "" Then
        Dim a As String
        Dim rs As Recordset
        Set rs = CurrentDb.OpenRecordset("Select * from Many where IDOne = " & ID.Value)
            If rs.EOF = False Then
                    MsgBox "Record Already Exist"
                Else
                    Dim rsInsert As Recordset
                    Set rsInsert = CurrentDb.OpenRecordset
                    CurrentDb.Execute "INSERT INTO Many ( IDChanels, Chanels ) SELECT mstChanels.Type,  mstChanels.ChanelName FROM mstChanels WHERE (((mstChanels.del)=False));", dbFailOnError
                    MsgBox "Record Updated"
            End If
End If
End Sub

Answer : MS Access 2007 Button Click Insert/Append Data Into Table

Mehram,

Why do you open this recordset? As far as I can see in your code, you are not retrieving records with recordset rsInsert..
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Private Sub Command27_Click()
If ID.Value = "" Then
        MsgBox ("Please check Trans #")
        Exit Sub
ElseIf ID.Value <> "" Then
        Dim a As String
        Dim db as Database
        Dim rs As Recordset
        set db = currentdb
        Set rs = db.OpenRecordset("Select * from Many where IDOne = " & ID.Value)
            If rs.EOF = False Then
                    MsgBox "Record Already Exist"
            Else
                    CurrentDb.Execute "INSERT INTO Many ( IDChanels, Chanels ) SELECT mstChanels.Type,  mstChanels.ChanelName FROM mstChanels WHERE (((mstChanels.del)=False));", dbFailOnError
                    MsgBox "Record Updated"
            End If
          'Clean up
          rs.close
          db.close
          set rs = nothing
          set db = nothing 
End If
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us