I have a VB application that I have installed the Report design control into to allow users to create reports at run time. I want to place a pre connected report in the designer with the database connections already created as a template. Here is the code I am trying to use to make a database connection via ODBC to a SQL database with an odbc connection called "Leas" Can anybody see what I am doing wrong. This is example code that that I am trying to tweak to work for me. When I try to run it is stops at the first "Set ADOConnection" and states that I am "trying to use an invalid outside procedure"
Dim ADOConnection As ADODB.Connection
Dim ADOCommand As ADODB.Command
''Beginning of Database connections
' Open the data connection
Set ADOConnection = New ADODB.Connection
ADOConnection.Open "Provider=MSDASQL;Persist Security Info=False;Data Source=Leas Database;Mode=Read"
' Create a new instance of an ADO command object
Set ADOCommand = New ADODB.Command
Set ADOCommand.ActiveConnection = ADOConnection
ADOCommand.CommandText = "Orders"
ADOCommand.CommandType = adCmdTable
' Add the datasource to the report
Report.Database.AddADOCommand ADOConnection, ADOCommand