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

Object Varaible or With block varaible not set (VB6/AccessDB)

Status
Not open for further replies.

webstaff

Technical User
Jan 2, 2003
97
GB
Hi Guys,

One of my forms just wont work when my programe is installed and ran on other puters.

The connection string I set for the ADODC in its properties is

PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=sbt.mdb;

This works on the machine im making the app in but no other the form will simply open but there are no records , it seems like the database connection is not being made.

1 error message I get when i try to add a record is Object Varaible or With block varaible not set

Any thoughts appreciated.

Thanks again
C

 
Where exactly is "sbt.mdb"? One hopes it is not on your machine. I would suggest using the full path.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
Hi Andy,

The database is in the root folder of the app, when the app is installed the database is copied there.

The full path that the ADODC properties sets it to is:

PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\litters\sbt.mdb;

Thats fine it works but when installed on another pute its no use.
I thought that using the app.path would fix it but it errors out.

PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= & app.path "\sbt.mdb;"

Would the ADODC connection string be better written on the form or it it best to do all the work in the ADODC properties set up?

Thanks again
C


 
I would suggest that you should allow the program to prompt for the db path. I store the path in an INI file and read in the value, check if the path exists, and if it doesn't prompt the user to locate the database. This can be jolly handy if you want to play with a copy of the db. I've never used a data control in my life, but I would advise against hard-coding such things. And example of how I do it:
Code:
Dim strX As String
  
On Error GoTo ErrHandler
  
' Start FileSystemObject
If gfsoX Is Nothing Then Set gfsoX = New Scripting.FileSystemObject
    
' Set App ini file name
gstrIniName = gfsoX.BuildPath(App.Path, App.EXEName & ".ini")
  
' Get database path from ini file
strX = GetIniValue("DBPATH")
  
' Locate database manually
If Not gfsoX.FileExists(strX) Then
  With mdiMain.dlgMain
    .DefaultExt = ".mdb"
    .DialogTitle = "Locate Application Database"
    .Filter = "Microsoft Databases (*.mdb)|*.mdb|All Files (*.*)|*.*"
    .FilterIndex = 1
    .flags = cdlOFNFileMustExist
    .InitDir = App.Path
    .ShowOpen
    strX = .FileName
  End With
  If strX = vbNullString Then End
End If
  
' Open database connection
Set gconX = New ADODB.Connection
gconX.CursorLocation = adUseServer
 
gconX.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & strX & ";Jet OLEDB:Database Password=password;"
' Did we open connection okay?
If gconX.State <> adStateOpen Then
  ' Nope - advise user and quit
  Set gconX = Nothing
  MsgBox &quot;Open Method of Connection object failed.&quot;, vbExclamation, cstrRoutineName
  End
Else
  ' Yes - save this path
  PutIniValue &quot;DBPATH&quot;, strX
End If
Hope this helps

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;A computer program does what you tell it to do, not what you want it to do.&quot; -- Greer's Third Law
 
WebStaff, sounds like you have a reference problem and your development machine has a different version of ms access installed than your user machines.
Nevertheless, ensure that both machines have the same code references set.
To do this, go into any code module of your development vb/access environment and open the references window. Confirm that Miscrosft ActiveX Data Objects 2.X Library is selected and is set at a higher priority than Microsoft DAO x.x Library.
On your user machine go through the same process but set the ADO object library at a higher priority than the DAO one. Save and compile your code.

 
Hi,jlitondo,

I have VB6 installed on my development machine with office2000.

On the other 2 test machines I have office 98 and the other 2003.

I make and comple the app on the development machine and install the app on the other 2 to test the app only, I dont have VB installed on them.

Can my app not run under different versions of MSACCESS?
What if the user only has office 98 and ive made the app with ACCESS 2000?

I think im getting a little confused now.

Thanks again






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top