General discussion

  • Creator
  • #2305705

    VB6 and ADODC Object Control


    by kojosteve ·

    Each time i try to connect my form on VB6 to a database in Access
    2000, i am unable to access the fields.
    What are the steps i need to follow
    Thank you

All Comments

  • Author
    • #3357907

      VB6 and ADODC Object Control

      by rrv ·

      In reply to VB6 and ADODC Object Control

      1) Install VB SP5.
      2) Use Jet driver 4.0 to connect to your database in ADODB
      3) Open a ADODB recordset or use seek method to get data from a table or view.
      4) “For each flddb in Recordset.fields” will give access to all fields of the open table.

      [To do the below line have a reference to MS actX Data Objects 2.7 Library]
      dim DB as adodb.Connection
      dim Rs as adodb.Recordset
      set DB=new ADODB.Connection
      DB.Open “Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mdb path;User ID=Admin;Jet OLEDB:Database Password=’password’;Persist Security Info=false;Locale Identifier=1033”
      set Rs=new ADodb.Recordset
      Rs.Cursorlocation=aduseclient “select T1.fld1,T2.fld2 from ((T2 right join T1 on T1.fld1=T2.fld2)) where T.Ffld1=”xyz”, DB,adOpenForwardOnly,adLockReadOnly

      ‘Now you have full RS recordset
      dim fldOpr as ADODB.Field
      dim fldProp as ADODB.Property

      for each fldOpr in RS.fields
      for each fldProp in fldOpr.Properties
      msgbox “Field : ” & fldOpr & ” – Property : ” & fldProp.Value & “(” & fldProp.Type & “)”

      So copy the above code in your VB and change appropriate fields. It will definitely work.

    • #3357423

      VB6 and ADODC Object Control

      by miss kitty ·

      In reply to VB6 and ADODC Object Control

      On your form, I assume you have installed a ADODC control. On the properties of the control make sure you have selected
      1. Use connection string and click on build.
      2. Provider=Microsoft.Jet.OLEDB.4.0;
      3. Test the connection. If it comes back ok then you should be able to connect text boxes on your form to the database table.
      4. In your text box properties, set the datasource to the ado control and your datafield to the table field you want.

    • #3357158

      VB6 and ADODC Object Control

      by itpreneur ·

      In reply to VB6 and ADODC Object Control

      I assume two things:
      A..If you are working in design time and put ADODC object control in your forms. You should do the following:
      a. Right Click ADODC OBJECT CONTROL
      B. sELECT adodc properties
      Choose ODBC if you have setup data source name.
      or choose build connection string and select OLEDB OR Microsoft Jet 3.5/4.0 and choose the Access file name.
      By then, VB will point you to recordsource and commandtype=TABLE and choose the table name. or you can use commandtype=TEXT and put an sql statement like this select * from tablename.

      If you want programming, you can write the following short code.

      Dim cmd As New ADODB.Command, rs As New ADODB.Recordset
      cmd.ActiveConnection = “Provider=MSDASQL.1;Persist Security Info=False;Data Source=SSA”

      ‘add the database
      Dim sqlsource As String

      sqlsource = “SELECT fieldname FROM tblname ”
      cmd.CommandType = adCmdText
      cmd.CommandText = sqlsource
      Set rs = cmd.Execute()

Viewing 2 reply threads