Solved

Updating a table in MSAcess using fields from forms

Posted on 1998-11-12
3
135 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
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 100 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 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