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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADODC Connection problem

Status
Not open for further replies.

CharonErebus

Technical User
Feb 27, 2003
8
GB
I am working with Visual Basic 6.0 and Access 2000. I am using ADODC to connect my program to the Access database. As it stands now, I have the ConnectionString property set at design time to a default database and at runtime open a common dialog box and change the connection to the database of their choice. If I take the ConnectionString out of the properties I get an error about "no default driver specified" or some such. How do I go about using the ADODC without declaring a ConnectionString beforehand?

--CharonErebus
 
You need to make sure that a connection string is provided before the object is used in code. For example, before you set the .recourdsource propertry or before the grid that is bound to it is refreshed, etc., etc.

I would check to see exactly where the error is occuring and see if the .connectionstring is set properly.

debug.print ADODC1.Connectionstring

You can provide this connection string at runtime or design time. Thanks and Good Luck!

zemp
 
As far as I can tell, I don't use the ADODC before I provide the ConnectionString. It is the first thing in the Form_load() event. Here is the code I'm using to make the connection:

Code:
'This is in the general declarations
Dim strX As String
Dim rstX As New ADODB.Recordset

'Here is the Form_load() event
Private Sub Form_Load()
On Error GoTo Canceled
cdlOpen.ShowOpen
rstX.CursorType = adOpenStatic
rstX.LockType = adLockOptimistic
strX = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & cdlOpen.FileName & ";Persist Security Info=False"
rstX.CursorLocation = adUseClient
rstX.Open "Select * FROM Subscribers", strX
Set Adodc1.Recordset = rstX

frmSub.Width = Screen.Width - (frmSub.Width / 20)
DataGrid1.Width = frmSub.ScaleWidth - (DataGrid1.Width / 20)
DataGrid1.Left = (frmSub.ScaleWidth - DataGrid1.Width) / 2
cmdQuit.Left = (DataGrid1.Left + DataGrid1.Width) - cmdQuit.Width
cmdClear.Left = (DataGrid1.Left + DataGrid1.Width) - cmdClear.Width
cmdQuery.Left = (DataGrid1.Left + DataGrid1.Width) - cmdQuery.Width
lstQuery.Left = DataGrid1.Left
txtQuery.Left = lstQuery.Left + lstQuery.Width + (lstQuery.Width / 20)
Canceled:
End Sub

What should I change to allow the user to set the database to be accessed without coding the ConnectionString at design time?

--CharonErebus
 
The connection string 'strX' that you provide is used for your ADODB recordset and not your ADODC (data control). If you are trying to use a ADODC and a bound datagrid then there is no need for an ADODB recordset. You should try something like the following to set up your ADODC,

strX = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & cdlOpen.FileName & ";Persist Security Info=False"
Adodc1.ConnectionString = strX
Adodc1.RecordSource = "Select * FROM Subscribers"

Then you can load your datagrid with code similar to this,

Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh Thanks and Good Luck!

zemp
 
Try this as well


strX = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ cdlOpen.FileName & ";Persist Security Info=False"
Adodc1.ConnectionString = StrX
Adodc1.RecordSource = "Select * FROM Subscribers"
Adodc1.Recordset.Requery


PMM (Palmsoft)
 
or, instead or

ADODC1.Recordset.Requery

use

ADODC1.Refresh

These are not always necessary when you are setting the .recordsource property for the first time, but are necessary when you are resetting or changing the .recordsource property. Thanks and Good Luck!

zemp
 
Thanks for the suggestions, guys. Turns out that I needed to set DataGrid1.DataSource to null in the properties and declare it to be ADODC1 at run time. :) It's always the simple stuff you don't think of.

--CharonErebus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top