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

Strings to MS Access Database

Posted on 2000-02-15
4
153 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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