Re: MS Access Query

From: Jinmin Yang (JinminYang_at_discussions.microsoft.com)
Date: 12/17/04


Date: Fri, 17 Dec 2004 07:29:04 -0800

I made a sample
Step 1: Build one universal ADO class (called: ClassADO)
Dim ConnDB As New ADODB.Connection
Public Function QueryRS(sSQL As String) As Recordset
    Dim rs As ADODB.Recordset
    On Error GoTo LoadSQLError
    Set rs = ConnDB.Execute(sSQL) Set QueryRS = rs
    Set rs = Nothing
    Exit Function
LoadSQLError:
    Set QueryRS = Nothing
End Function

Public Sub RunExecute(ByVal SQL As String)
    On Local Error GoTo Err_Execute
    ConnDB.Execute SQL
    Exit Sub
Err_Execute:
    End Select
End Sub

Private Sub Class_Initialize()
    Set ConnDB = New ADODB.Connection
    ConnDB.Mode = adModeReadWrite
    ConnDB.CursorLocation = adUseClient
    CAll ConnectDB
End Sub

Private Sub Class_Terminate()
    On Local Error Resume Next
    ConnDB.Close
    Set ConnDB = Nothing
End Sub

Private Sub ConnectDB()
    Dim strConn As String
    On Error GoTo Errorhandler:
   strConn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
                "Data Source=" & App.Path & "myDB.mdb;"
    ConnDB.Open strConn
    Exit Sub
Errorhandler:
End Sub
 Step 2: Vb 6.0 code
1) Read Data from MS-Access
   Dim oRead As New ClassADO
   Dim rs As Recordset
    Set rs = oRead.QueryRS("Here is your query statemant")
    If Not rs.EOF Then
       Start read your data
    End IF
    SET oRead = Nothing
2) Write Data into MS-Access
   Dim oRead As New ClassADO
    Call oRead.RunExecute("Here is your query statemant")
    SET oRead = Nothing

"Gérard Leclercq" wrote:

> Do you mean Stored Procedures??
> http://authors.aspalliance.com/stevesmith/articles/sprocs.asp
>
>
>



Relevant Pages

  • Project Error
    ... Private Declare Sub Sleep Lib "Kernel32" ... Dim strDataSrc As String ...
    (microsoft.public.vb.bugs)
  • Re: Is there a way to prevent a RichTextBox from scrolling?
    ... Private _isRegex As Boolean ... Public Sub New(ByVal thispattern As String, ... Dim entry As tDict ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Excel Listing tool using VB
    ... Sub ListFiles2() ... Dim directories() As String, CurrentDirectory As String ... Dim dirtopaste, dirok ...
    (microsoft.public.vb.general.discussion)
  • Form Error
    ... SMSDS_CallerID As String ... Private Declare Sub Sleep Lib "kernel32" ... Dim ComString As String ... Dim AppPath As String, FreeFileNo% ...
    (microsoft.public.vb.bugs)
  • Re: Encrypt/hide Password
    ... Public Sub New(ByVal strCryptoName As String) ... ' instantiated crypto class. ... Dim fsKey As New FileStream(strSaveToPath, FileMode.OpenOrCreate, _ ...
    (microsoft.public.scripting.wsh)