|
-
Mar 15th, 2001, 07:58 AM
#1
Thread Starter
Fanatic Member
Gentle - Men/Ladies
I am trying to use the DataEnvironment in VB to create
a report.. The connection string I'd like to use to enter my data already exists in a variable in my program... How can I use it in My Data Environment... I do not want to create it in design time as the user will have a choice up front to choose server and database where he/she wants to connect
If this is not clear, please let me know...I will rephrase...
Thank in advance
-
Mar 15th, 2001, 09:16 AM
#2
cnnAgency is the connection object in the data environment and this is the code for its events.
Code:
Private Sub cnnAgency_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
If adStatus = adStatusErrorsOccurred Then
'if there is connection problem go to db setup
SaveSetting "Tracker Series", "Paths", "Agency", ""
MsgBox "The connection to the specified database failed! The Database settings may be incorrect, please contact your network administrator and try again.", vbCritical, "Connection Failed"
cnnSQL.Cancel
Else
SaveSetting "Tracker Series", "Paths", "Agency", pConnection.ConnectionString
End If
End Sub
Private Sub cnnAgency_WillConnect(ConnectionString As String, UserID As String, Password As String, Options As Long, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
'pConnection.Properties("Prompt") = adPromptNever
ConnectionString = GetSetting("Tracker Series", "Paths", "Agency")
End Sub
This actually gets the connection string from a registry setting and if it fails uses the ADO default connection dialog thing to reset a new one and then trys again. If you just want it to fail instead of prompt to fix the connection then active the line with adPromptNever in it. Just try to figure it out if not just post me your questions.
-
Mar 15th, 2001, 10:54 AM
#3
Thread Starter
Fanatic Member
...
Thanks my friend...
I will try it now...
-
Mar 15th, 2001, 12:16 PM
#4
Thread Starter
Fanatic Member
..
Sorry...
How do u run the created report from within VB?
May be a naive question... (am a first-time user of DataReport)
Thanks
-
Mar 15th, 2001, 01:30 PM
#5
Thread Starter
Fanatic Member
...
Edneeis,
What do u actually have in registry under
"Tracker Series", "Paths", "Agency", ""??
I created a global variable holding my connection string
i.e
SaveConnString = "Provider........" and the whole deal
change the ConnectionString = SaveConnString
I get an Invalid Data source when I try to print the report...
Thanks
-
Mar 15th, 2001, 03:47 PM
#6
Are you talking about an access report? Crystal report? Data Report?
What is your data source? Access? SQL?
Yes the setting is the whole connection string.
Where did you get the connection string from? Is it invalid?
What SHOULD happen is if the connection string is just incorrect it should show a dialog that askes for the location of the database (on access) or the server (on SQL) and the after the user sets the information it and it connects successfully it writes THAT connection string to the registry.
Although now that you mention it and I tweaked with it more I have found that (first cnnSQL should actually be cnnAgency in the example) depending upon where the connection failed it prompted me for different things. Like if there was no connection string at all it would sometimes ask for the ODBC driver but if the connection string was for SQL or Access and the database or server was just wrong it worked. I'll mess with it and brush it up and get back to you.
-
Mar 16th, 2001, 07:57 AM
#7
Thread Starter
Fanatic Member
...
Talking to SQL Server 6.5
Data Report is what I am using...
The connection string would be ok (unless the format is different from that of the data environment) since I am using it to connect to the server in the first place...
So, the user starts the application...
She gets prompted to pick a server and she logs in
I connect to SQL Server....
On The screen, there is OK button.. when clicked.. Want to invoke the datareport... and print it...
The connection string I saved is the one used to connect to the server in the first place when the user logs in... I had saved it into a global variable...
and I am hoping to use it to get data for my report...
Thanks in advance..
-
Mar 16th, 2001, 09:00 AM
#8
Did everything else work but the data report?
-
Mar 16th, 2001, 09:57 AM
#9
Thread Starter
Fanatic Member
...
Thanks...
Yes, everything worked fine... and I just got the data report to work as well (thanks to your example)...
In the click event of the ok button, I did this:
AdhCognosEnv.Connections("AdhCognosConn").ConnectionString = gs_SaveConnectionString
AdhCognosEnv.Connections("AdhCognosConn").Open
where AdhCognosEnv is my data environment
and gs_SaveConnectionString is the connection string I told you I saved...
So, I used a default server to create my report in the
design environment.. then at run time I overrride the connection based on the user's choice...
The AdhCognosEnv.Connections("AdhCognosConn").Open gets me to the WillConnect event and I then show my report in the click event with
AdhCognosRpt.Show 1 (modally)
Thanks Edneeis... Your help was great!
-
Mar 16th, 2001, 11:13 AM
#10
Thread Starter
Fanatic Member
One more question...
I have a label on the report...
I'd like to be able.. to alter its contents dynamically...
modify it with the client name for which the report is being run..
Any ideas??
Thanks much
-
Mar 16th, 2001, 01:33 PM
#11
Thread Starter
Fanatic Member
..
Just in case someone may be doing a search one day....
Found a solution:
In the same click event of the OK button
AdhCognosRpt.Sections("Section2").Controls("Label5").Caption = cboChains.Text
where AdhCognosRpt is the name of the data report
and the sections refers to the page header (Section2)
on my report and "label5" is the name of the label whose contents I want to change....
cboChains.text is the selected client the user chooses to run the report for...[from a combo box]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|