Results 1 to 4 of 4

Thread: mdb connections

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Posts
    88

    Exclamation

    Hi.

    I am having trouble with databases. I want to connect, open and set the recordset in code. Is this possible? i.e. Do I have to put the ADODC on the form? I presume it will be quicker and smaller to do it in code.

    If I write it in code, how do I set the text fields to the correct field? And without the ADODC does .refresh etc work as normal?

    I have set public connection/database/recordset names.

    My current code is;

    Code:
    cnBSSAC.Open "provider=microsoft.jet.oledb.4.0;" & "Data Source=c:\database\bssac.mdb"
    rstBSSAC.Open "commonBSSUser", dbBSSAC, adOpenKeyset, adLockPessimistic, adCmdTable
    txtFields(3).DataSource = "commonBSSUser"
    txtFields(3).DataField = "Name"
    Thanks in advance,

    Paul.
    Set MCP = NTServer + NTWorkstation

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96
    You need to put an ADODC on the form and set its data source etc.. (you can make it invisible on the form)

    to assign text fields do somthing like

    Code:
    with rstBSSAC
       txtBox1.text = !FieldName1
       txtBox2.text = !FieldName2
       txtBox3.text = !FieldName3
       txtBox4.text = !FieldName4
    ...
    end with
    as for .refresh etc.. they should still work but I'm not too sure about it.

    H.
    Just trying to muddle through...

  3. #3
    Guest

    Cool here it is

    U can do it without having ADODC on the form. here it is..
    for this u have to put Microsoft Activex Data Objects Refrences to ur project

    code:

    Option Explicit

    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    Private Sub Form_Load()

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<database path>;Persist Security Info=False"

    rs.Open "Select * from Employee", cn, adOpenKeyset, adLockOptimistic

    rs.MoveFirst

    Text1.Text=rs(0).value
    Text1.Text=rs(1).value
    Text1.Text=rs(2).value

    End Sub



  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Posts
    88

    Thumbs up

    Thanks guys..

    Im actually making progress now..

    Paul.
    Set MCP = NTServer + NTWorkstation

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