Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

*** INSERT INTO ***

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
0
0
GB
help anyone pleaseeee.<br>
<br>
Right, i've got a form displaying 1 record (about 7 fields). I'm just trying to move this record to another table. The INSERT INTO sql thingy isn't working. can someone give me an example piece of code for me, much appreciated<br>
<br>
the table that the record is on now is called 'Type1' and the table that I want the record to be moved into is called 'Type111'. Lets say there 4 fields in the record.<br>
<br>
Thanks for any help
 
Why not write an append query called &quot;AppRec&quot; for example and then run the query from some event handler in your form --<br>
<br>
docmd.openquery &quot;AppRec&quot;<br>
<br>
If you want to suppress the messages from Access right before it's about to append the record, write<br>
<br>
docmd.setwarnings false<br>
docmd.openquery &quot;AppRec&quot;<br>
docdm.setwarnings true<br>
<br>
<br>
If you want to write your own SQL in Visual Basic, just create the query as you would any other and then click on the SQL tab and you'll see how to write it correctly in SQL. Then you can copy it from there to your VB code.
 
Don't know what happened to the rest of my code. Here it is again...<br>
<br>
Dim sql as string<br>
<br>
sql =
 
You may want to consider using DAO code :<br>
<br>
So on the click event of a command button - cmdAdd<br>
<br>
Sub cmdAdd_Click()<br>
Dim dbs As Database<br>
Dim rst111As Recordset<br>
<br>
Set dbs = CurrentDb<br>
Set rst111= dbs.OpenRecordset(&quot;Type111&quot;)<br>
<br>
rst111.AddNew<br>
<br>
rst111!Fields1 = Me!txtField1<br>
rst111!Fields2 = Me!txtField2<br>
rst111!Fields3 = Me!txtField3<br>
rst111!Fields4 = Me!txtField4<br>
<br>
rst111.Update<br>
<br>
rst111.Close<br>
<br>
<br>
End Sub<br>
<br>
The recordset rst111 is set to you table Type111<br>
The fields in the table are referenced rst111!Field1 …. rst111!Field4<br>
txtField1 to txtField4 are text box controls on the current for ( Me )<br>
<br>
<p>Bill Paton<br><a href=mailto:wpaton@neptune400.co.uk>wpaton@neptune400.co.uk</a><br><a href=
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top