Solved

acsess Insert show - from VB

Posted on 2001-07-18
12
185 Views
Last Modified: 2008-02-26
Hello i have got a simple form with one text box on it
and a acess 2000 db with one table called main with

id and name as fields

i wont to be able to hard code the name in the code but let the number for the id table come from the form ??

i also would like a serach so number = 1 show name ??

SILKI
0
Comment
Question by:silki
  • 5
  • 4
  • 3
12 Comments
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6293563
Try

SELECT Name FROM Main WHERE id = Val(Text1.Text)

Vin.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6293570
Add a reference to Microsoft Activex Data Object 2.x Library to your project. At least version 2.1 or higher is required for access 2000 databases:

Here is a very simple example which opens the connection on form load and closes it with the form. When you click the command button, the contents of text1 are used in the where clause of the select statement to retrieve the corresponding record and the value of the name field is put into text2. This can be expanded on at will but should give you an idea of how to proceed.

Private cnnAccess As ADODB.Connection

Private Sub Form_Load()
  Set cnnAccess = New ADODB.Connection
  cnnAccess.ConnectionString = "Provider=Jet.OLEDB.4.0;Data Source=c:\MyFolder\MyMDB.mdb"
  cnnAccess.Open
End Sub

Private Sub Form_Unload()
  cnnAccess.Close
  Set cnnAccess = Nothing
End Sub

Private Sub Command1_Click()
  Dim rstMain As ADODB.Recordset
  Set rstMain = New ADODB.Recordset
  rstMain.Open "Select Name From Main Where ID = " & CStr(Text1.Text),cnnAccess,adOpenStatic,adLockReadOnly
  Text2.Text = rstMain.Fields("Name").Value
  rstMain.Close
  Set rstMain = Nothing
End Sub
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6293579
Argh you got there before me...

Vin.
0
 

Author Comment

by:silki
ID: 6293716
How do i do this ???


"Add a reference to Microsoft Activex Data Object 2.x Library to your project. At least version 2.1 or
higher is required for access 2000 databases:"
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6293983
In the Project menu select references.

Move down the list until you find it.

Vin.
0
 

Author Comment

by:silki
ID: 6294062
Ok i now get

run-time erro '3706'

ADO could no t find the specified provider.

on  cnnAccess.Open
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:silki
ID: 6294063
HHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLPPPPPPPP
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6294242
You need to download MDAC from

http://www.microsoft.com/data

and install it on your computer.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6294253
I missed a bit from the connection string, use this as your connection string, but substitute your database and path instead of nwind.mdb

cnnAccess.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;Persist Security Info=False"
0
 

Author Comment

by:silki
ID: 6294320
BRILLIAN TimCottee !!

Work fine now

I take it i can now use normal SQl statements like

INSERT
Delete

ETC ....
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6297310
You can use any sql statements you like, there are a number of different ways of using them though, some are better than others for different things:

rstMain.Open "Select * From Main",cnnAccess,adOpenStatic,adLockOptimistic

For example returns a recordset, you can choose whether it is a keyset/dynamic/static recordset and also the locking type.

cnnAccess.Execute "INSERT INTO Main (ID,Name) Values(400,'TimCottee')"

Executes a sql statement on the connection but doesn't return a recordset, you can use the execute method to return a recordset as well but it is forward-only/read-only and may not be much use to you.

Anyway this should be enough to get you started, you should probably close this question now, and open new ones for any subsequent specific problems that you have.
0
 

Author Comment

by:silki
ID: 6297382
Thanks - A great help !!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 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…
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now