By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,188 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,188 IT Pros & Developers. It's quick & easy.

OT- Access Program stuck on little VB 2005 project

P: n/a
I normally only use A2000 but I need to do a little project in VB2005

But I can't figure out how to open the backend Access table in code and add
data using code. I don't need to bind to a form.
This is so simple in VBA but I have searched help, internet and 2 books and
have yet to find a working example for VB 2005

Does anyone have a simple sample of opening a table and adding data.

I know this an Access group but some here also work with VB 2005

Jul 24 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi, Karl.
>I normally only use A2000 but I need to do a little project in VB2005

But I can't figure out how to open the backend Access table in code and
add data using code.
For a quicker answer, I suggest you post your question in a VB .Net
newsgroup that focuses on databases.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact
info.
Jul 25 '07 #2

P: n/a
Hi Karl,

This is a piece of cake

--------------------------------------------
Imports System.Data.OleDb
Imports System.Data
Imports System.IO

Public Class Form1

Dim conn As OleDbConnection, da As OleDbDataAdapter
Dim ds As DataSet, curMgr As CurrencyManager

Private Sub Form1_Load(...) Handles MyBase.Load

conn = New OleDbConnection
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0; Data Source =
C:\someDir\db1test.mdb"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandType = CommandType.Text
da.SelectCommand.CommandText = "Select * from yourTbl"
da.Fill(ds, "tbl1")
curMgr = CType(Me.BindingContext(ds.Tables("tbl1")), CurrencyManager)
curMgr.Position = 0
'--tssL3.Text = curMgr.Count.ToString
'--tssL2.Text = (curMgr.Position + 1).ToString
dgrv1.DataSource = ds.Tables(0)

End Sub

End Class

--------------------------------------------

This is a basic sample for just reading data into a VB2005 app from an
Access mdb. As far as controls go, for this sample, start a new project
which will bring up Form1 by default. In Form1 add a statusStrip control
(from the toolbox) -- this is the replacement for the Statusbar control
-- lots more horsepower. Actually, if you want to simplify the example,
you can forgo the statusstrip and just comment out the lines of code for
tssL3... and tssL2...

But you will need to add a datagridview to the form. I named my
datagridview -- dgrv1. THen just copy and paste the code above. Just
replace the connection string path with a path to your mdb and replace
yourTbl with the name of a table in your Access mdb and then run the
sample. The datagridview will populate immediately with the data from
your Access table.

The CurrencyManager object "curMgr" is how you keep track of where you
are in your dataset. You display the record position in the labels in
the statusstrip. I named my labels tssL2 and tssL3. But just to run
the sample, you don't need the statusstrip.

Writing/editing data from your Access table is also pretty easy, but
I'll let you chew on this for a while first. Note: if the connection
string copies on 2 lines -- drag the 2nd line to the first line to make
it one line because in this sample I did not break the connection string
into 2 lines. And you do not need to add any additional objects like a
Dataset from the toolbox. The only control you need from the toolbox
for this sample is a Datagridview control. Drag one of those onto your
form and strech it out a little bit.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 25 '07 #3

P: n/a
Few of us who participate in this newsgroup use DotNet. For the type
applications we do, single-user, modest-group-size multiuser, and
client-server on a LAN, Access is quicker and easier.

Thus, I think Gunny's advice is good, if your application is web-based. If
your application is an individual Windows app, or on a LAN, then perhaps you
ought to invest a little time and effort into investigating creating
database applications with Access itself.

Larry Linson
Microsoft Access MVP

"Karl" <so*****@sbcglobal.bizwrote in message
news:Cd******************@newssvr23.news.prodigy.n et...
>I normally only use A2000 but I need to do a little project in VB2005

But I can't figure out how to open the backend Access table in code and
add data using code. I don't need to bind to a form.
This is so simple in VBA but I have searched help, internet and 2 books
and have yet to find a working example for VB 2005

Does anyone have a simple sample of opening a table and adding data.

I know this an Access group but some here also work with VB 2005

Jul 25 '07 #4

P: n/a
Thanks Rick

"Rich P" <rp*****@aol.comwrote in message
news:46*********************@news.qwest.net...
Hi Karl,

This is a piece of cake

--------------------------------------------
Imports System.Data.OleDb
Imports System.Data
Imports System.IO

Public Class Form1

Dim conn As OleDbConnection, da As OleDbDataAdapter
Dim ds As DataSet, curMgr As CurrencyManager

Private Sub Form1_Load(...) Handles MyBase.Load

conn = New OleDbConnection
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0; Data Source =
C:\someDir\db1test.mdb"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandType = CommandType.Text
da.SelectCommand.CommandText = "Select * from yourTbl"
da.Fill(ds, "tbl1")
curMgr = CType(Me.BindingContext(ds.Tables("tbl1")), CurrencyManager)
curMgr.Position = 0
'--tssL3.Text = curMgr.Count.ToString
'--tssL2.Text = (curMgr.Position + 1).ToString
dgrv1.DataSource = ds.Tables(0)

End Sub

End Class

--------------------------------------------

This is a basic sample for just reading data into a VB2005 app from an
Access mdb. As far as controls go, for this sample, start a new project
which will bring up Form1 by default. In Form1 add a statusStrip control
(from the toolbox) -- this is the replacement for the Statusbar control
-- lots more horsepower. Actually, if you want to simplify the example,
you can forgo the statusstrip and just comment out the lines of code for
tssL3... and tssL2...

But you will need to add a datagridview to the form. I named my
datagridview -- dgrv1. THen just copy and paste the code above. Just
replace the connection string path with a path to your mdb and replace
yourTbl with the name of a table in your Access mdb and then run the
sample. The datagridview will populate immediately with the data from
your Access table.

The CurrencyManager object "curMgr" is how you keep track of where you
are in your dataset. You display the record position in the labels in
the statusstrip. I named my labels tssL2 and tssL3. But just to run
the sample, you don't need the statusstrip.

Writing/editing data from your Access table is also pretty easy, but
I'll let you chew on this for a while first. Note: if the connection
string copies on 2 lines -- drag the 2nd line to the first line to make
it one line because in this sample I did not break the connection string
into 2 lines. And you do not need to add any additional objects like a
Dataset from the toolbox. The only control you need from the toolbox
for this sample is a Datagridview control. Drag one of those onto your
form and strech it out a little bit.

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Jul 25 '07 #5

P: n/a
Sorry that should say Thanks Rich
Jul 25 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.