Solved

From DBGrid to Access

Posted on 2001-08-24
6
274 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
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:sanjeevjain1973
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much. I am quite busy now. So, I will try out the code later. Thanks again.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:planocz
Comment Utility
irenesiah are you still busy?
0
 

Author Comment

by:irenesiah
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

763 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

11 Experts available now in Live!

Get 1:1 Help Now