?
Solved

Updating a table in MSAcess using fields from forms

Posted on 1998-11-12
3
Medium Priority
?
140 Views
Last Modified: 2010-04-30
I'm trying to use the DoCmd.RunSQL to insert a run in a table, using two of the fields on a form.  The table I'm trying to insert in is not associated with the form?  How do I refer to the fields on the form.  One of the fields is from a combo box and is hidden (i.e. primekey)
0
Comment
Question by:rpolley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:Poddy
ID: 1444567
I would recommend using DAO.

and the execute method of a database object

Is there a reason why you are not?
0
 
LVL 3

Accepted Solution

by:
vbWhiz earned 400 total points
ID: 1444568
Using DAO you can have code that looks like this and does exactly what you want.

Sample Code:


Dim WS AS Workspace
Dim DB AS Database
Dim RST As Recordset

'Workspace allows you to open databases (Like the MSAccess login)
Set WS = DBEngine.createWorkspace("","Admin","")

'DB opens the MDB
Set DB = WS.OpenDatabase("C:\MyDatabase.mdb")

'Rst opens the table
Set RST = DB.openrecordset("tblToAddto")

'Rst.Addnew adds a new record to this table
Rst.AddNew

'Set fields in the table to equal the text in text1 & 2
Rst!Field1 = Me.text1.text
Rst!Field2 = Me.text2.text

'commit the change to the database
Rst.Update

'close our variables
Rst.Close
DB.Close
WS.Close

For this code to work you must add 'Microsoft DAO 3.5 Object Library' to your vb app from the references menu.


I hope this helps you out!
0
 

Author Comment

by:rpolley
ID: 1444569
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question