468,253 Members | 1,241 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

connecting vb with to access database without using adodc...

vikas1111
122 100+
This is the code which i have written.....
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim c As New ADODB.Connection
  3. Dim cm As ADODB.Command
  4. Dim rs As New ADODB.Recordset
  5. Private Sub regno_Change()
  6. c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/Comion.mdb;Persist Security Info=false")
  7. rs.Open "select * from main_table", c, adOpenDynamic
  8. Me.regno.Text = rs(3)
  9. End Sub
  10.  
The error i am getting " User defined type not defined- -- for the first line of my code itself"
Can anyone pls help me????
Feb 22 '08 #1
30 3328
debasisdas
8,127 Expert 4TB
Have you added the reference of ADO library ?
Feb 22 '08 #2
vikas1111
122 100+
Have you added the reference of ADO library ?
ya microsoft activex data object 2.library
Feb 22 '08 #3
debasisdas
8,127 Expert 4TB
Run in debug mode and check which line is throwing the error.
Feb 22 '08 #4
vikas1111
122 100+
Run in debug mode and check which line is throwing the error.
now error in this line
c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/Comion.mdb;Persist Security Info=false")

The path which i have mentioned is correct....And i have already removed password..
Feb 22 '08 #5
debasisdas
8,127 Expert 4TB
Try using this
Expand|Select|Wrap|Line Numbers
  1. c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\Comion.mdb;Persist Security Info=false"
  2.  
Feb 22 '08 #6
vikas1111
122 100+
Try using this
Expand|Select|Wrap|Line Numbers
  1. c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\Comion.mdb;Persist Security Info=false"
  2.  
Hi
I changed it but i am getting the same error in the same line.... The error reads like this::::::
Run time error 3705
Feb 22 '08 #7
debasisdas
8,127 Expert 4TB
error in which line of code ?
Feb 22 '08 #8
rizwan6feb
108 100+
If you are still having problem, try this

1. Paste ADODC control on your form
2. Connect it to your database using properties dialog
3. If it successfully connects to the database, copy the connection string and use it in place of the code which is creating problem
4. Remove the ADODC control from your form
Feb 22 '08 #9
debasisdas
8,127 Expert 4TB
To get the correct connection string it is better to use a UDL file .
Feb 22 '08 #10
vikas1111
122 100+
If you are still having problem, try this

1. Paste ADODC control on your form
2. Connect it to your database using properties dialog
3. If it successfully connects to the database, copy the connection string and use it in place of the code which is creating problem
4. Remove the ADODC control from your form
hey Rizwan..
It worked thanks...
I want to know another thing.. If i want to link another column of the same table and in the same form with another text box then what should i do ?
Feb 22 '08 #11
QVeen72
1,445 Expert 1GB
Hi,

You are not supposed to Open a Connection in a Change Event....
Try to add a ".bas" module Declare Connections as Public , In MDI Form Load Open the Connection..

Yes, the error 3705 is : Object already open..
So , Before Opening Check the State of the Connection..

Expand|Select|Wrap|Line Numbers
  1. If c.State <> adStateOpen Then
  2.     Set c =Nothing
  3.     c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data  Source=d:\Comion.mdb;Persist Security Info=false")
  4. End If
  5.  
Feb 22 '08 #12
debasisdas
8,127 Expert 4TB
Just assign the column name or index of the column in the record set tothe text box.
Feb 22 '08 #13
vikas1111
122 100+
Just assign the column name or index of the column in the record set tothe text box.

Ya i tried it but its not working ...
Feb 22 '08 #14
debasisdas
8,127 Expert 4TB
What is the error message ?
Feb 22 '08 #15
vikas1111
122 100+
What is the error message ?

No error msg.. But i am not able to connect the second text box to the database.. This is the code which i have written...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim c As New ADODB.Connection
  3. Dim cm As ADODB.Command
  4. Dim rs As New ADODB.Recordset
  5. Private Sub Form_Load()
  6. Dim cs As String
  7. c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data _  
  8.  Source=d:/Comion.mdb;Persist Security Info=false")
  9. rs.Open "select * from company", c, adOpenDynamic
  10.   ' this is the first text box named text1
  11. Me.Text1.Text = rs(1)
  12.  ' this is the second text box
  13.  ' which i want to connect it to
  14.  ' another column in the same table.
  15. Me.name.Text = rs(5)
  16. End Sub
  17.  
I am not able to connect the second text box named ( name ) to another column in the same table......
Feb 22 '08 #16
debasisdas
8,127 Expert 4TB
What is that me.name in your code ?

Use name of a text box ?

How there is no error ?
Feb 22 '08 #17
vikas1111
122 100+
What is that me.name in your code ?

Use name of a text box ?

How there is no error ?
I have named text box 2 as name or you can concider it as text box 2. only.... Error i am getting is invalid qualifier..
My problem is that i need to connect name ( or text box 2) to another column is the same table.. How can i connect it...
Feb 22 '08 #18
QVeen72
1,445 Expert 1GB
Hi,

I guess, you are using ADODC..

Set these Properties of TextBox:

DataSource = ADODC1 (Select From the Drop - Down Available)
DataField = Field12 (Select From the Drop - Down Available)

Regards
Veena
Feb 22 '08 #19
vikas1111
122 100+
Hi,

I guess, you are using ADODC..

Set these Properties of TextBox:

DataSource = ADODC1 (Select From the Drop - Down Available)
DataField = Field12 (Select From the Drop - Down Available)

Regards
Veena

Hi Veena..
No i have not used adodc.. And i am not able to set those 2 properties which you have mentioned.. Actually there is drag down option available but the list is not appearing in both the data properties..as we get in adodc.....
Feb 22 '08 #20
debasisdas
8,127 Expert 4TB
there must be some error in your code

if you use proper name for controls and proper indexing or recordset there will never be any error .
Feb 22 '08 #21
debasisdas
8,127 Expert 4TB
No i have not used adodc...........................................th e list is not appearing in both the data properties..as we get in adodc.....

are you sure what are you doing .

tell me first what are you using

ADODC or ADODB ???
Feb 22 '08 #22
vikas1111
122 100+
are you sure what are you doing .

tell me first what are you using

ADODC or ADODB ???

Actually i had problem with ::::: c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\Comion.mdb;Persist Security Info=false

so i followed the procedure as mentioned in post 9.
Feb 22 '08 #23
debasisdas
8,127 Expert 4TB
Is the code working now ?
Feb 22 '08 #24
vikas1111
122 100+
Is the code working now ?

Ya the code is working after following that procedure mentioned in post 9.
Feb 22 '08 #25
QVeen72
1,445 Expert 1GB
Hi,

First change the Name of your TextBox from "name" to "txtName"
and check this :

Me.txtName.Text = rs(5)

rs(5) means 6th Field from the RecordSet (Zero Based Index)

By the way what is your Error..?
I Guess, "Me.Name.Text" would Cause Error, as Name is the Property of the Form Object..

REgards
Veena
Feb 22 '08 #26
vikas1111
122 100+
Hey Veena i changed it and its working..thanks...
Feb 22 '08 #27
vikas1111
122 100+
Hi,

First change the Name of your TextBox from "name" to "txtName"
and check this :

Me.txtName.Text = rs(5)

rs(5) means 6th Field from the RecordSet (Zero Based Index)

By the way what is your Error..?
I Guess, "Me.Name.Text" would Cause Error, as Name is the Property of the Form Object..

REgards
Veena


if in case i want to link other column from other table in the same form what should i do ?
Feb 22 '08 #28
QVeen72
1,445 Expert 1GB
if in case i want to link other column from other table in the same form what should i do ?
Hi,

One More Recordset with Same Connection object and Show the Result:

Expand|Select|Wrap|Line Numbers
  1. Dim RSNew As New ADODB.RecordSet
  2. RSNew.Open "Select * From NewTable", C
  3. If Not RSNew.EOF Then
  4.     txtNew1.Text  =RSNew(0) & ""
  5.     txtNew2.Text  =RSNew(1) & ""
  6. End If
  7.  
Regards
Veena
Feb 22 '08 #29
vikas1111
122 100+
Hi,

One More Recordset with Same Connection object and Show the Result:

Expand|Select|Wrap|Line Numbers
  1. Dim RSNew As New ADODB.RecordSet
  2. RSNew.Open "Select * From NewTable", C
  3. If Not RSNew.EOF Then
  4.     txtNew1.Text  =RSNew(0) & ""
  5.     txtNew2.Text  =RSNew(1) & ""
  6. End If
  7.  
Regards
Veena

Thanks a lot its working..
Feb 22 '08 #30
Rina18
1
can anyone send me the full code of adding a record in vb without using adodc
Dec 18 '20 #31

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.