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
Solved

Updating a table in MSAcess using fields from forms

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a task in Outlook from access 11 42
How to Add / Edit Windows Menu 4 67
Problem to line 23 53
Collapse and expand table in Word 2010 2 28
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

791 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