Solved

From DBGrid to Access

Posted on 2001-08-24
6
283 Views
Last Modified: 2012-06-27
Greetings!

I have created a DBGrid on the form for entering data. But how am I going to transfer all the data in DBGrid to the database? I am using VB6 and Access '97.

Thank you.
0
Comment
Question by:irenesiah
[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
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:sanjeevjain1973
ID: 6421674
You can use Bound & unbound mode of DB Grid.
In Bound mode you can bound dbgrid with Data control. And Set Allownew, Allow Update , AllowDelete property of DB GBrid true , false accordingly your requirment.


Sanjeev
0
 
LVL 27

Expert Comment

by:planocz
ID: 6421750
Hi irenesiah,
Here is a piece of code that will update a DB table.
With this and the rest of your code you should be able
to copy your DBGrid to the Database.

Dim iCol as integer

set RS = new ADODB.Recordset

With RS
    For iCol = 0 To 2
       .Fields(iCol).Value = DBGrid.Columns(iCol).Value
    Next
    .Update
End With
0
 

Author Comment

by:irenesiah
ID: 6427886
Thank you very much. I am quite busy now. So, I will try out the code later. Thanks again.
0
Technology Partners: 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!

 
LVL 27

Expert Comment

by:planocz
ID: 6465274
irenesiah are you still busy?
0
 

Author Comment

by:irenesiah
ID: 6474705
planocz, sorry for the delay. I am still new in VB. So, how do I reference ADODB in VB? TQ!
0
 
LVL 27

Accepted Solution

by:
planocz earned 20 total points
ID: 6475538
from your menu goto project, then references and add the microsoft ActiveX DataObject 2.5 or 2.6 Library.
If you are using a module then add this code to that module....

'******* This goes into your module class file ****
Public RS             As ADODB.Recordset
Public conDataBase    As ADODB.Connection
Public sSql           As String
Public sDBPass        as String    <--- For a password var. if you want to use one in your database.

Public Sub OpenDB()
  '***** XXXX is your Access Database Name
  Set conDataBase = New ADODB.Connection
  conDataBase.CursorLocation = adUseClient
  conDataBase.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
              "Data Source=" & App.Path & "\XXXX.mdb;" & _
 "Jet OLEDB:Database Password=" & sDBPass

End Sub

Public Sub OpenRecSet(sSql As String)
   Set RS = New ADODB.Recordset
   RS.Open sSql, conDataBase, adOpenDynamic, adLockOptimistic
End Sub

'****** This will goto your form file where your DBgrid is.
Dim iCol as integer

  OpenDB

   sSql = "SELECT * From YOUR_TABLE_NAME_IS_HERE order by YOUR FIELD_NAME_IS_HERE"    <---- use for sorting
   
    OpenRecSet (sSql)


With RS
   For iCol = 0 To 2
      .Fields(iCol).Value = DBGrid.Columns(iCol).Value
   Next
   .Update
End With


Hopefully this will get you started...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…
Suggested Courses
Course of the Month6 days, 23 hours left to enroll

623 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