Solved

Strings to MS Access Database

Posted on 2000-02-15
4
157 Views
Last Modified: 2010-05-02
I have 3 strings (sA, sB, sC) with some content.

I would like to know how to insert these strings in a MS Access
Database in the following manner.

Col 1 = sA
Col 2 = sB
Col 3 = sC

Do you know what I mean?

0
Comment
Question by:blue021097
[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
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2524805
Are these 3 strings different fields ? Or these strings one field ? Which must be inserted into one field ? Here is some sample code. This uses OLEDB provider.

Dim Cn as New ADODB.Connection
Dim sCon as string,sSql as string
sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\my documents\mb.mdb;"
Cn.Open scon
Col1 = sA
Col2 = sB
Col3 = sC
sSql = "Insert Into <tablename> Values ('" & col1 & "','" & col2 & "','" & col3 & "')"
Cn.Execute sSql,adExecuteNoRecords
cn.close
Set cn = nothing
This code will insert records into 3 fields. Explain me if this is not what you looking for.
0
 
LVL 1

Accepted Solution

by:
eab111098 earned 100 total points
ID: 2524808
first, col 1,2,3 are not columns persey, they are fields. in excel, they're columns, in access, they're fields. to make the following code work, you need to make a reference to the jet 351 dao control under project->references. with that done... here ya go.

public function addtomydb(byval col1 as string, byval col2 as string, byval col3 as string)

dim DB as database
dim RS as recordset

set db = opendatabase("yourdbpathandname")
set rs = db.openrecordset("nameoftablewhereyouwanttoputthisstuff")
with rs
  .addnew
  .fields("fieldname1") = col1
  .fields("fieldname2") = col2
  .fields("fieldname3") = col3
  .update
end with
rs.close
set rs = nothing
db.close
set db = nothing
end function

now, there are at least 101 other ways of doing this addition, and undoubtedly, you'll receive many more suggestions. i'm not going to tell you this is the best way because the best way is dictated by your application and what you're trying to accomplish. this is just one way.

hope this helps.
later.
ed.
0
 
LVL 6

Expert Comment

by:Marine
ID: 2524840
Dude its not necessary to lock the question. If it will be the right answer he can accept your comment. If the question is locked others can't see it since most of them don't browse answered question. I beat your time though :-) i got my answer in first. Blue my example uses ADO method of access his example uses DAO you havent' specified what you were using. My method would be faster for one reason only. It uses SQL to update and it doesn't create a recordset which is a plus.
0
 

Author Comment

by:blue021097
ID: 2568966
Marine,

Your answer may very well be right but I have
accepted eab answer as it is the first
I tried out, and it worked. Problem solved.

I hope this is okay?

0

Featured Post

Independent Software Vendors: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
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…

695 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