Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
insert tables
joseph 

16 years ago
In a form i have a textbox that displays the name of a table.  This is a constant changing textbox.  I need to insert the displayed named table into a known table named ops.  bouncing my head off the wall trying to do this. Here is my current code:

Private Sub Command3_Click()
Dim db As Database
 
   Dim rst As Recordset
  Set db = CurrentDb()
  Set rst = db.OpenRecordset(list, dbOpenTable)
DoCmd.RunSQL "insert into ops select * from "


End Sub

I cannot complete the "from" statement becuase this is the table listed in the textbox.

Beginer
access 2007
thanks much


Answer from Richard Rost:

You've got two completely different methods for trying to do the same thing here. Either use a Recordset OR an SQL statement. You don't need both.

Personally, I would use the Recordset.

Set db=CurrentDb()
Set rs=db.OpenRecordset("TableName",dbOpenTable)
rs.AddNew
rs!FieldName = Forms!FormName!FieldName
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing

That's just off the top of my head and I haven't tested it, but that should give you the jist of what you need to do. For more help on Recordsets, see the following tutorial:

Recordsets are basically objects you can use in VBA code to edit, add, and delete records. They give you the power to do pretty much anything you want to your data using VBA code.

Here's a FREE video tutorial on how to use Recordsets:

http://599cd.com/tips/access/recordsets?key=BlFAlEx

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 10/5/2026 3:25:13 PM. PLT: 1s