Forum Moderators: open

Message Too Old, No Replies

Copy row and 1 field different

         

marnix

1:24 pm on Sep 11, 2009 (gmt 0)

10+ Year Member



HI,

I have a VB6 application where I want to make a copy of a row in a SQL 2005 database. But I want to make 1 field different of the original before entering the row this is named strNewSaveAs.
I have this code so far to copy (not to change row omschrijving).
***************************************************
Private Sub Copy_Into()

Dim strCopyProduct As String
Dim adoCn As adoDb.Connection
Dim adoRs As adoDb.Recordset
Dim adoCm As adoDb.Command
Dim strSQL As String
Dim strNewSaveAs As String
Dim IntInstelbladId As Integer

strCopyProduct = Text2(0).Text

strNewSaveAs = InputBox("Save nieuwe als:", "Geef volledige naam als", "Mech. instelling LWS* - naam: setupnr")

Set adoCn = New adoDb.Connection
With adoCn
.ConnectionString = "Provider=SQLOLEDB.1;Password=Ombouw;Persist Security Info=True;User ID=Ombouw;Initial Catalog=NIG_Ombouw;Data Source=svtlb003\v01"

.CursorLocation = adUseServer
.Open
End With

Set adoCm = New adoDb.Command
With adoCm
Set .ActiveConnection = adoCn
.CommandType = adCmdText

.CommandText = "INSERT INTO T_Instelblad_work select * From T_Instelblad_work Where [Omschrijving] = '" & strCopyProduct & "'"
.Execute
.CommandText = "INSERT INTO T_Omschrijving (OmschrijvingID,Omschrijving) Values ('10 ','" & strNewSaveAs & "') " 'Where [Omschrijving] = '" & strCopyProduct & "'"
.Execute
.CommandType = adCmdStoredProc
.CommandText = "spADOTempTest"

End With

Set adoRs = New adoDb.Recordset
With adoRs
Set .ActiveConnection = adoCn
.LockType = adLockOptimistic
.CursorLocation = adUseServer
.CursorType = adOpenForwardOnly
End With

adoCn.Close
Set adoCn = Nothing
Set adoRs = Nothing

End Sub