Cannot find table

Hi all,

I am using CR 10 and VB 6.

To run a report I have a function that contains the following code:

    For Each crxDatabaseTable In Report.Database.Tables
        With crxDatabaseTable.ConnectionProperties
            .Item("Provider") = "SQLOLEDB"
            .Item("Initial Catalog") = DataBaseName
            .Item("Data Source") = Server
            .Item("User ID") = username
            .Item("Password") = password
            .Item("Connect Timeout") = "5"
        End With
        crxDatabaseTable.Location = crxDatabaseTable.Name
    Next crxDatabaseTable

When the line crxDatabaseTable.Location = crxDatabaseTable.Name is removed, the report fails giving an error "the table '' could not be found" and when the line is inserted, reports that have tables with aliases fail giving the same error.  What do I do?

Thanks in advance.
vbtigerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vidruConnect With a Mentor Commented:
Were the reports created in a version prior to CR 9?  There are some KB articles that mention a problem with the connection information that's saved with the older reports.  The fix with those is to delete the ConnectionProperties before setting them:
        With crxDatabaseTable.ConnectionProperties
            .DeleteAll      
            .Item("Provider") = "SQLOLEDB"
            ...
            ...
        End With

What kind of database are you connecting to?
0
 
vidruCommented:
The trouble with .Location = .Name failing with aliased tables is not unique to CR10.  Usually, it works great for avoiding errors at runtime, especially if the db schema was saved with the report.

What is in the table's Location currently that you're trying to get rid of?  Is it somethting like "DBName.dbo.TableName"?  You might have to revert to parsing the Location, or replacing the schema with the correct schema at runtime:

Dim strLocation As String
strLocation = LCase(crxDatabaseTable.Location)
If InStr(strLocation, ".dbo.") > 0 Then
    crxDatabaseTable.Location = (strLocation, InStr(str, ".dbo.") + 5)
End If

In any case, you've just hit one of the few instances where setting Location = Name doesn't work.

-dave
0
 
vbtigerAuthor Commented:
Hi dave,

Thanks for the response.  The table location currently is only the table name.  There is no dbo or anything.  What is the workaround?

Thanks

vbtiger
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
vbtigerAuthor Commented:
Hi dave,

When I use .deleteall, then I get a subscript out of range error (because all items have been removed).

I'm connecting to a SQL Server database.
0
 
vbtigerAuthor Commented:
Dave,

I used .Add instead of .item and it works fine now.  Thanks for your help!
0
 
vidruCommented:
Glad to hearit.

-dave
0
 
vbtigerAuthor Commented:
I was wrong.  It still doesn't work!
0
 
vidruCommented:
Can you be a bit more descriptive?

-dave
0
 
vbtigerAuthor Commented:
When I use crxDatabaseTable.Location = crxDatabaseTable.Name, tables with aliases don't work and I get an error and I get an error "cannot find table alias_name" and when I remove it, the report picks up the default location.  But I managed to correct it by replacing the line with:
crxDatabaseTable.SetTableLocation crxDatabaseTable.Name, crxDatabaseTable.Location, adCon
0
All Courses

From novice to tech pro — start learning today.