Results 1 to 2 of 2

Thread: Access 2000 ADO CurrentProject Connection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Germany, New Zealand, now in Australia
    Posts
    143

    Access 2000 ADO CurrentProject Connection

    Hi there,

    Can anybody be of any HELP. I would like to figure out the following.

    Insteat of using any wizards or else I would like to connect some text boxes "within" Access 2000 with VBA. I have two tables which I like to connect to and fill my text boxes.
    There are some ideas I have but ................
    My concern is what Sub Procedure do I take in VBA ??? etc.

    I got the following from an MS Site.
    Code:
    Sub
    '---
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    
    With rst
    ' Open table-type Recordset object.
    .Open Source:=strTblName, _
          ActiveConnection:=cnn, _
          CursorType:=adOpenKeyset, _
          LockType:=adLockOptimistic, _
          Options:=adCmdTableDirect
    
    'How do  I specify my tables and than of course my text boxes etc. ???
    
    Set cnn = Nothing
    End Sub
    Thanks aktell

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Access 2000 ADO CurrentProject Connection

    Code:
    public sub UpdateTextBoxes()
        dim rst as adodb.recordset
        dim strSql as string
    
        on error resume next
    
    '---- sql,connection,static,optimistic,adcmdtext
        rst.open strSql, CurrentProject.Connection, 3, 3, 1 
    
        if rst.state=adstateopen then
            if rst.eof then
                msgbox "No records",vbokonly+vbinformation,"Error"
            else
                txtBox1.text = nz(rst("field1"),"")
                txtBox2.text = nz(rst("field2"),"")
            end if
            rst.close
        end if
    
        if err.number<>0 then msgbox "Error : " & err.number & vbcrlf & err.description,vbokonly+vbexclamation,"Error"
    
        set rst = nothing
    end sub
    Something like that... Tweak the names of the controls to what you have set, the sql statement is a select query, or you can use a query/tablename but then the last parameter needs to be changed to adcmdtable.

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width