Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Strings to MS Access Database

Posted on 2000-02-15
4
Medium Priority
?
166 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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

609 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