473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Insert into a database

Hello All,

Given the following code from several differenet sources within this
newsgroup, we were able to come up with a way to connect to a database and
retrieve data from it. The code is listed below:

(******************************************)
01. Dim MyConn, rs, sql
02. Set MyConn = CreateObject("ADODB.Connection")
03.
04. MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"
05. MyConn.Properties("Data Source") = "\\server\share\APPS_DB.mdb"
06. MyConn.Open
07.
08. Set rs=CreateObject("ADODB.recordset")
09. sql = "SELECT * FROM tbl_web_app"
10. rs.Open sql, MyConn
11.
12. Dim ID, Pwd, Account
13.
14. user_ID = (rs("ID"))
15. user_Pwd = (rs("Pwd"))
16. user_Account = (rs("Account"))
17.
18. some other work related code blah blah blah
19.
20. rs.Close
21. Set MyConn = Nothing
22. Set rs = Nothing

(*******************************************)

Now, what I am wondering is if there is a way using the code above to insert
data into the tbl_web_app in the APPS_DB.mdb file? I tried the following
but it doesn't work; nothing gets inserted into the database . I replaced
the following:

line 09. with sql = "INSERT INTO tbl_web_app (ID, Pwd, Account) Values
('user_ID', 'user_Pwd', 'user_Account')"

I also removed lines11 - 17. I don't think I need them for the INSERT part.
we have some other code before the database connection that sets the
variables for user_id, user_Pwd, and user_Account.

Any and all help in this matter is greatly appreciated,

Argus
Aug 16 '06 #1
2 1769
* OdAwG:
Hello All,

Given the following code from several differenet sources within this
newsgroup, we were able to come up with a way to connect to a database and
retrieve data from it. The code is listed below:

(******************************************)
01. Dim MyConn, rs, sql
02. Set MyConn = CreateObject("ADODB.Connection")
03.
04. MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"
05. MyConn.Properties("Data Source") = "\\server\share\APPS_DB.mdb"
06. MyConn.Open
07.
08. Set rs=CreateObject("ADODB.recordset")
09. sql = "SELECT * FROM tbl_web_app"
10. rs.Open sql, MyConn
11.
12. Dim ID, Pwd, Account
13.
14. user_ID = (rs("ID"))
15. user_Pwd = (rs("Pwd"))
16. user_Account = (rs("Account"))
17.
18. some other work related code blah blah blah
19.
20. rs.Close
21. Set MyConn = Nothing
22. Set rs = Nothing

(*******************************************)

Now, what I am wondering is if there is a way using the code above to insert
data into the tbl_web_app in the APPS_DB.mdb file? I tried the following
but it doesn't work; nothing gets inserted into the database . I replaced
the following:

line 09. with sql = "INSERT INTO tbl_web_app (ID, Pwd, Account) Values
('user_ID', 'user_Pwd', 'user_Account')"

I also removed lines11 - 17. I don't think I need them for the INSERT part.
we have some other code before the database connection that sets the
variables for user_id, user_Pwd, and user_Account.

Any and all help in this matter is greatly appreciated,

Argus

There are several different ways of accomplishing this, but this should
work:

SQL = "Insert INTO tbl_web "INSERT INTO tbl_web_app " & _
"(ID, Pwd, Account) Values" & _
"('user_ID', 'user_Pwd', 'user_Account')"
MyConn.Execute SQL

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Aug 17 '06 #2
hey thanks for the reply, the solution was the following:

sql = "INSERT INTO tbl_web_app (ID, Pwd, Account) Values ('" & user_ID &"',
'" & user_Pwd & "', '" & user_Account & "')"
MyConn.Execute SQL

I had to add '" & variable_name &"' since I was using variable

Again, thanks for you help.

Argus
"Randy Harris" <pl****@send.no.spamwrote in message
news:gU******************@newssvr21.news.prodigy.c om...
* OdAwG:
Hello All,

Given the following code from several differenet sources within this
newsgroup, we were able to come up with a way to connect to a database
and
retrieve data from it. The code is listed below:

(******************************************)
01. Dim MyConn, rs, sql
02. Set MyConn = CreateObject("ADODB.Connection")
03.
04. MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"
05. MyConn.Properties("Data Source") = "\\server\share\APPS_DB.mdb"
06. MyConn.Open
07.
08. Set rs=CreateObject("ADODB.recordset")
09. sql = "SELECT * FROM tbl_web_app"
10. rs.Open sql, MyConn
11.
12. Dim ID, Pwd, Account
13.
14. user_ID = (rs("ID"))
15. user_Pwd = (rs("Pwd"))
16. user_Account = (rs("Account"))
17.
18. some other work related code blah blah blah
19.
20. rs.Close
21. Set MyConn = Nothing
22. Set rs = Nothing

(*******************************************)

Now, what I am wondering is if there is a way using the code above to
insert
data into the tbl_web_app in the APPS_DB.mdb file? I tried the
following
but it doesn't work; nothing gets inserted into the database . I
replaced
the following:

line 09. with sql = "INSERT INTO tbl_web_app (ID, Pwd, Account) Values
('user_ID', 'user_Pwd', 'user_Account')"

I also removed lines11 - 17. I don't think I need them for the INSERT
part.
we have some other code before the database connection that sets the
variables for user_id, user_Pwd, and user_Account.

Any and all help in this matter is greatly appreciated,

Argus
There are several different ways of accomplishing this, but this should
work:

SQL = "Insert INTO tbl_web "INSERT INTO tbl_web_app " & _
"(ID, Pwd, Account) Values" & _
"('user_ID', 'user_Pwd', 'user_Account')"
MyConn.Execute SQL

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

Aug 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
4
by: authorking | last post by:
I use the following code to insert a data record in to a datatable of an access database.But every time I execute the command, there will rise an exception and the insert operation can't be...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
5
by: Bonzol | last post by:
Hello, PHP n00b here. Using SQL just working off some examples, I have no problem selecting data, but I cant seem to be able to insert. If someone could see where im going wrong <!DOCTYPE...
14
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
0
by: radiodes | last post by:
I am very new to SQL/Access, and only use it very limitedly, so apologies ahead of time. I have a website that inserts data into an access database, using the code below. Basically, I've got...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.