I have a VB6 front end, SQL Server 2005 as the back end and Crystal Reports 8.5 for reports.
I need to set the location at run time in my application as I have 2 databases. My problem is that when I change database, but the location remain the same. It will be great if anyone can help me out. Thanks in advance for your time, and here is my code.
Private Sub prin_Click()
With CrystalReport1
.Connect = MDI1.txtcn --> this is my connection info "driver={sql server};server=server;database=database;uid=user;pwd=password"
.DiscardSavedData = True
.Action = 1
.PrintReport
End With
Try some code like this:
Private Sub cmdSetLocations_Click()
Dim CrxApp As New CRAXDRT.Application
Dim CrxRep As CRAXDRT.Report
Dim CrxSubRep As CRAXDRT.Report
Dim strReport As String
Dim i As Integer, ii As Integer
strReport = "[Path to report file]"
Set CrxRep = CrxApp.OpenReport(strReport)
SetReportLocation CrxRep
For i = 1 To CrxRep.Sections.Count
For ii = 1 To CrxRep.Sections(i).ReportObjects.Count
If CrxRep.Sections(i).ReportObjects(ii).Kind = crSubreportObject Then
Set CrxSubRep = CrxRep.OpenSubreport(CrxRep.Sections(i).ReportObjects(ii).SubreportName)
SetReportLocation CrxSubRep
End If
Next ii
Next
'open your report in the report viewer
Set CrxApp = Nothing
Set CrxRep = Nothing
Set CrxSubRep = Nothing
End Sub
Private Sub SetReportLocation(ByRef RepObj As CRAXDRT.Report)
Dim CrxDDF As CRAXDRT.DatabaseTable
Dim CP As CRAXDRT.ConnectionProperties
For Each CrxDDF In RepObj.Database.Tables
Set CP = CrxDDF.ConnectionProperties
CP.DeleteAll
CP.Add "Connection String", "[Your connection string goes here]"
Next
Set CrxDDF = Nothing
Set CP = Nothing
End Sub
With CR
.ReportFileName = App.Path + "\Labsen2.rpt"
.SelectionFormula = "{PersonalCalendar.PersonalCalendarDate}>= Date(" & Year(DTPicker1) & "," & Month(DTPicker1) & "," & Day(DTPicker1) & ") and {PersonalCalendar.PersonalCalendarDate}<=date(" & Year(DTPicker2) & "," & Month(DTPicker2) & "," & Day(DTPicker2) & ") and {Department.DepartmentName}= '" & Combo1.Text & "'"
.Formulas(0) = "tglAwal = '" & DTPicker1.Value & "'"
.Formulas(1) = "tglAkhir = '" & DTPicker2.Value & "'"
.Password = Chr(10) & "ithITtECH"
.RetrieveDataFiles
.WindowState = crptMaximized
.Action = 1
End With
Try formatting the connection string like this:
DSN=server;UID=database;PWD=password;DSQ=user
The meanings of DSN, UID, DSQ are counter-intuitive, they are overloaded by Crystal.
Also check you have no subreports whose Connect properties would need to be similarly changed.
Why not pass the recordset to your report? In this way you will be able to get data from any supported (i mean VB6 can connect to) databases dynamically, you can even merge data from multiple databases, your report will require the data(recordset) only and report will be created with Data Field Definition.
Related
How to add multiple email addresses in CC list for VB Script send mail.
option explicit
' --------------------------------------------------------------------------
' -- Create Lotus Notes email (and add attachment) using VB Script
' --
' -- Version 1.01
' --
' -- Created by : Michael Green
' -- migreen#westpac.com.au
' --
' -- Based on in-complete/partially working script from :
' -- http://en.allexperts.com/q/Using-Lotus-Notes-1427/Creating-LotusNotes-email-using-1.htm
' --
' -- Created : 06/10/2009
' -- Last Updated: 07/10/2009
' --------------------------------------------------------------------------
Dim oSession ' AS NotesSession
Dim strServer
Dim strUserName
Dim strMailDbName
Dim oCurrentMailDb ' as NOTESDATABASE
Dim oMailDoc ' as NOTESDOCUMENT
Dim ortItem ' as NOTESRICHTEXTITEM
Dim ortAttacment ' as NOTESRICHTEXTITEM
Dim oEmbedObject ' as ????
dim cstrAttachment
Dim blAttachment
cstrAttachment = "c:\Temp\Telstra.xls"
blAttachment = True
' Start a session to notes
wscript.echo "## Connecting to Lotus Notes session..."
Set oSession = CreateObject("Notes.NotesSession")
wscript.echo("NotesVersion : " & oSession.NotesVersion)
wscript.echo("NotesBuildVersion: " & oSession.NotesBuildVersion)
wscript.echo("UserName : " & oSession.UserName)
wscript.echo("EffectiveUserName: " & oSession.EffectiveUserName)
wscript.echo "## GetEnvironmentString..."
strServer = oSession.GetEnvironmentString("MailServer",True)
wscript.echo("Server :" & strServer)
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
' Create a document in the back end
Set oMailDoc = oCurrentMailDb.CREATEDOCUMENT
' Set the form name to memo
OMailDoc.form = "Memo"
with oMailDoc
.SendTo = "migreen#westpac.com.au"
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = "migreen#westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
set ortItem = oMaildoc.CREATERICHTEXTITEM("Body")
with ortItem
.AppendText("Test of RTF Item append")
.AddNewLine(2)
.AppendText("Signature")
End With
' Create additional Rich Text item and attach it
If blAttachment Then
Set ortAttacment = oMailDoc.CREATERICHTEXTITEM("Attachment")
' Function EMBEDOBJECT(ByVal TYPE As Short, ByVal CLASS As String, ByVal SOURCE As String, Optional ByVal OBJECTNAME As Object = Nothing) As Object
' Member of lotus.NOTESRICHTEXTITEM
Set oEmbedObject = ortAttacment.EMBEDOBJECT(1454, "", cstrAttachment, "Attachment")
End If
wscript.echo "## Sending email..."
with oMailDoc
.PostedDate = Now()
.SAVEMESSAGEONSEND = "True"
.send(false)
end with
wscript.echo "## Sent !"
' close objects
set oMailDoc = nothing
set oCurrentMailDb = nothing
set oSession = nothing
Just use an array to set the values
with oMailDoc
.SendTo = Array( "migreen#westpac.com.au", "mgreen#westpac.com.au", "green#westpac.com.au" )
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = "migreen#westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
Originally I did not want to comment on the quality of the copied code at all. But the discussion with Lankymart made me think, it would be good to comment on it.
Set oSession = CreateObject("Notes.NotesSession")
This line creates an OLE interface to a running Notes- Client. If client does not run, then it will be started. If you used Set oSession = CreateObject("Lotus.NotesSession") then it would have been a COM- Object you get. Be aware, that Some OLE- Methods do not work in COM and vice versa. e.g. oCurrentMailDb.OPENMAIL is OLE, while the same thing in COM would be oCurrentMailDb.OpenMailDatabase()
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
Getting the users' mailfile is completely nonsense, the code will get everything but a correct filename. As the variable is not used at all - can be forgotten
set oCurrentMailDb = oSession.CurrentDatabase
Just gets the database that is currently open in the client. If no database is open, an error will be thrown in the next wscript.echo- line, and we will never get to the next lines where it checks, if a database is open...
The problem with this line: Sending mails is possible from ANY database in Lotus Notes. If the database that is open e.g. is the personal addressbook, then the mail will be saved and sent from there (and you will never find it in the Sent- View of your mailfile.
I would suggest to use OPENMAIL first and only do a fallback to the currently open database if that fails.
The rest of the code seems to be OK.
Create an array of email address strings and set CopyTo to that array:
Dim addresses (2)
addresses(0) = "EMAIL"
addresses(1) = "EMAIL"
addresses(2) = "EMAIL"
with oMailDoc
.SendTo = "migreen#westpac.com.au"
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = addresses
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
I working on getting the full directory path of the key file of a component, of an advertised shortcut using VBScript, from outside an MSI.
I read we can make use of the MsiGetComponentPath & MsiGetShortcutTarget function. Below is the code that I put together, but I ain't getting the output that I want - that is the path of the key file based on the component column in the shortcut table. Any help is appreciated.
Set Installer = CreateObject("WindowsInstaller.Installer")
Set Database = Installer.OpenDatabase("C:\StackExchange_Test.msi", 0)
Set View = Database.OpenView("SELECT `Target`,`Component_` From `Shortcut`")
View.Execute
Set rec = View.Fetch
Do While (rec Is Nothing) = False
MsgBox(rec.StringData(1) & " " & rec.StringData(2) & " " & rec.StringData(3) _
& " " & rec.StringData(4) & " " & rec.StringData(5))
Path = Installer.ComponentPath (FnMSIFetch("ProductCode"), rec.StringData(2))
Msgbox (Path)
Set rec = View.Fetch
Loop
Function FnMSIFetch(varProperty)
Set Database = Installer.OpenDatabase("C:\StackExchange_Test.msi", 0)
Dim SQL
SQL = "SELECT * FROM Property WHERE Property = '" & varProperty & "'"
Dim View
Set View = Database.OpenView(SQL)
View.Execute
Dim Record
Set Record = View.Fetch
FnMSIFetch=Record.StringData(2)
End Function
Hi Please help me with the following. I used the below VB code to upload a text file to my oracle database.When i run my script i have the error message "Class not defined ADODB"
Set Obj_DBConn = New ADODB.Connection
Set cat = New ADOX.Catalog
Obj_DBConn.ConnectionString ="Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=##test##)(PORT=##test##))" & _
"(CONNECT_DATA=(SERVICE_NAME=##test##))); " & _
"uid=test;pwd=test;"
Obj_DBConn.Open Database_Path
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = Nothing
Set f = fso.OpenTextFile("C:\Documents and Settings\test.txt", ForReading, True)
For i = 1 To 10000
v_Line_String = f.ReadLine
v_Output_Each_part = Split(v_Line_String,";",-1,1)
v_Col_A = v_Output_Each_part(0)
v_Col_B = v_Output_Each_part(1)
v_Col_C = v_Output_Each_part(2)
Obj_DBConn.Execute "INSERT INTO test_me (ID_Q, NAME, ROLLNO) VALUES ('" & v_Output_Each_part(0) & "','" & v_Output_Each_part(1) & "','" & v_Output_Each_part(2) & "')"
Next
Please provide ur insights Thanks in advance
Your
Set Obj_DBConn = New ADODB.Connection
is VBA, not VBScript. Use
Set Obj_DBConn = CreateObject("ADODB.Connection")
to get this line passed the interpreter.
If you promise to delete the evil "On Error Resume Next", you may obtain further inspiration from here.
Update:
If you google for something like "80004005 odbc oracle" you'll find this trouble shooter with detailed step by step instructions to deal with connectivity problems. Next stop probably should be connectionstrings.com.
here is my code
Dim Cn1 As ADODB.Connection
Dim iSQLStr As String
Dim field_num As Integer
Set Cn1 = New ADODB.Connection
Cn1.ConnectionString = _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DefaultDir=" & "C:\path\"
Cn1.Open
iSQLStr = "Select * FROM " & "file.txt" ' & " ORDER BY " & txtField.Text
field_num = CInt(1) - 1
Set Rs1 = Cn1.Execute(iSQLStr)
lstResults.Clear
While Not Rs1.EOF
DoEvents
Rs1.Fields(field_num).Value = "qaz"
If IsNull(Rs1.Fields(field_num).Value) Then
lstResults.AddItem "<null>"
Else
lstResults.AddItem Rs1.Fields(field_num).Value
End If
Rs1.MoveNext
Wend
The error i get is in this line
Rs1.Fields(field_num).Value = "qaz"
it says "The current recordset does not support updating", what is wrong in the code?
I'm not sure if this is valid for text files but with SQL Server you need to change the LockTypeEnum Value setting to allow editing see this link, the default is adLockReadOnly
Edit
According to this link it is not possible to edit a text file via ADO.
Following the howto Extending the Active Directory Schema To Track Custom Info I'm able to setup a single-value schema attribute that is easily changeable via a context menu in ADUC. Multi-value schema attributes get considerably more complicated. Say (for the sake of argument) my value is "Projects" and each user may be a list as many projects as necessary.
Following is a sad little script that will set Project to a single value:
Dim oproject
Dim oUser1
Dim temp1
Set oproject = Wscript.Arguments
Set oUser1 = GetObject(oproject(0))
temp1 = InputBox("Project: " & oUser1.project & vbCRLF & vbCRLF & "Project")
if temp1 <> "" then oUser1.Put "project",temp1
oUser1.SetInfo
Set oUser1 = Nothing
Set oproject = Nothing
Set temp1 = Nothing
WScript.Quit
How can I modify this to allow, assign, and modify multiple values?
I gave up on an elegant UI and just went with the semicolon delimited list. Here's the code if anyone cares:
Dim objProject
Dim objUser
Dim temp1, title, message, default
Dim projects
title = "Projects"
Set objProject = Wscript.Arguments
Set objUser = GetObject(objProject(0))
'Find our current projects
projects = objUser.projects
If Not isArray(projects) Then
projects = Array(projects)
End If
'Setup our message box
message = "Semicolon-delimited list of Projects"
default = arrayToStr(projects)
temp1 = InputBox(message, title, default)
'catch cancels
if IsEmpty(temp1) Then
WScript.Quit
End If
' update our data
projects = strToArray(temp1)
objUser.Put "projects",projects
objUser.SetInfo
'Clean up and quit
Set projects = Nothing
Set objUser = Nothing
Set objProject = Nothing
Set temp1 = Nothing
Set title = Nothing
Set message = Nothing
Set default = Nothing
WScript.Quit
'Functions
Function strToArray(s)
Dim a
Dim token
' discard blank entries
For Each token in split(s, ";")
token = trim(token)
If token <> "" Then
If isEmpty(a) Then
a = token
Else
a = a & ";" & token
End If
End If
Next
' return array
strToArray = split(a, ";")
End Function
Function arrayToStr(a)
Dim s
Dim token
For Each token in a
If isEmpty(s) Then
s = token
Else
s = s & ";" & token
End If
Next
' return string
arrayToStr = s
End Function