Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to a database problem 1

Status
Not open for further replies.

Silvano

Programmer
Jul 16, 2001
386
US
When I run the following code I ger the "Object required (Error 424)" error. The debugger will point to the line that starts with "Set rs = cn.Execute("SELECT * ...". I know that the acctual error might precede this particular line. I am also trying to connent to the database without using DSN (acctualy, the database will be on the remote machine but I will deal with that problem later). I am kinda new to VB and I am thankful for any help I can get here...


Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'open the database and populate the Donors ListView

Set cn = New ADODB.Connection
cn.ConnectionString = "Driver=Microsoft Access Driver (*.mdb);DBQ=" & sDBLocation
cn.Open

Set rs = cn.Execute("SELECT * FROM Donor WHERE donorID = " & DonorData.donorID)

'adding data to the Donors ListView
While Not rs.EOF
Set itmX = lvDonors.ListItems.Add(, , rs!Donor_Name, 0, 0)
itmX.SubItems(1) = rs!Phone_Number
itmX.SubItems(2) = rs!Email

rs.MoveNext
Wend

rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing Sylvano
dsylvano@hotmail.com
 
Do the same as you did for the connection object:

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

Mark
 
Thanks for the reply. I tried what you have suggested here and it didn't worked. I am still getting the same error. I have Microsoft ActiveX Data Objects 2.7 Library as a reference. Could it be that I need some other reference? Sylvano
dsylvano@hotmail.com
 
Check your SQL statement. You use DonorData.DonorID in the SQL but it is not declared (although it may be passed in as a parameter and not shown) and the Object Required error probably stems from that...

Set rs = cn.Execute("SELECT * FROM Donor WHERE donorID = " & DonorData.donorID)

Mark
 
thx Mark. your observation was correct. the DonorData.DonorID was not declared... sorry 'bout that, I guess it's not my day... Sylvano
dsylvano@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top