Solved

Strings to MS Access Database

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

Industry Leaders: 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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

733 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