![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: issue |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| |||
| Code: Dim ObjDAO As Object
Dim ObjDataBase As Object
Dim ObjRecordSet As Object
Private Sub OpenDataMDBBase()
Set ObjDAO = CreateObject("DAO.DBEngine.35")
Set ObjDataBase = ObjDAO.OpenDatabase("C:\Temp\EmpData.mdb")
Set ObjRecordSet = ObjDataBase.OpenRecordset("DataBaseProject")
End Sub
Private Sub CmdEnd_Click()
End
Unload Me
End Sub
Private Sub cmdGo_Click()
'On Error GoTo ErrorHandalar
Screen.MousePointer = vbHourglass
Dim strQryString As String
If optName.Value = True Then
Dim strTempQryString As String
Dim I As Integer
Dim J As Integer
J = 1
strTempQryString = "{DatabaseProject.EmployeeName} ="
If lstEmployee.SelCount > 1 Then
For I = 0 To lstEmployee.ListCount - 1
If lstEmployee.Selected(I) = True Then
If J = 1 Then
strQryString = strTempQryString & "'" & lstEmployee.List(I) & "'"
J = J + 1
Else
strQryString = strQryString & " Or " & strTempQryString & "'" & lstEmployee.List(I) & "'"
End If
End If
Next I
Else
strQryString = strQryString & strTempQryString & "'" & lstEmployee.List(lstEmployee.ListIndex) & "'"
End If
With CrystalReport1
.ReportFileName = App.Path & "\EmpDetails.rpt"
.Connect = App.Path & "\EmpData.mdb"
.DiscardSavedData = True
.RetrieveDataFiles
.ReportSource = 0
.SQLQuery = "Select * from DataBaseProject order by EmployeeName"
.ReportTitle = "Employee Details Report"
.Destination = crptToWindow
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
If strQryString <> "{DatabaseProject.EmployeeName} ='Select All'" Then
.SelectionFormula = strQryString
End If
.Action = 1
End With
End If
If optDOB.Value = True Then
If txtFromDate.Text <> "" And txtToDate.Text <> "" Then
strQryString = "{DatabaseProject.EmployeeDOB} >= #" & Format(txtFromDate.Text, "mm/dd/yyyy") & "# And {DatabaseProject.EmployeeDOB} <= #" & Format(txtToDate.Text, "mm/dd/yyyy") & "#"
End If
With CrystalReport1
.ReportFileName = App.Path & "\EmpDetails.rpt"
.Connect = App.Path & "\EmpData.mdb"
.DiscardSavedData = True
.RetrieveDataFiles
.ReportSource = 0
.SQLQuery = "Select * from DataBaseProject order by EmployeeName"
.ReportTitle = "Employee Details Report"
.Destination = crptToWindow
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.SelectionFormula = strQryString
.Action = 1
End With
End If
Screen.MousePointer = vbDefault
Exit Sub
ErrorHandalar:
MsgBox CStr(Err.Number) + Err.Description
Screen.MousePointer = vbDefault
End Sub
Private Sub Form_Load()
Call CopyMdbFileInReportLocation
Call OpenDataMDBBase '//Open MDB DataBase
Call FillListBox '//Fill List Box With Employee Names
optName.Value = True
End Sub
Private Sub FillListBox()
lstEmployee.AddItem "Select All"
Do While Not ObjRecordSet.EOF
lstEmployee.AddItem ObjRecordSet.Fields("EmployeeName")
ObjRecordSet.MoveNext
Loop
lstEmployee.Selected(0) = True
End Sub
Private Sub CopyMdbFileInReportLocation()
'**************Imp Note**********************
'This procedure is used only to generate the report with out an error, because in crystal report
'I have specified hard coded database path location ("C:\Temp\EmpData.mdb").
'When you uninstall or delete the application pl delete database as well.
'*********************************************
Dim fso As Object, f As Object, MyFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FolderExists("C:\Temp")) Then
Set f = fso.CreateFolder("C:\Temp")
End If
If Not (fso.FileExists("C:\Temp\EmpData.mdb")) Then
Set MyFile = fso.GetFile(App.Path & "\EmpData.mdb")
MyFile.Copy ("C:\Temp\EmpData.mdb")
End If
If (fso.FileExists(App.Path & "\EmpData.mdb")) Then
fso.DeleteFile (App.Path & "\EmpData.mdb")
End If
End Sub __________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes |
| |||
| Hi, I am not in touch with VB about 1 year. But I surf from Internet for your result.The example is for Access Database.But you can try SQL Databse when you finished reading the following link. Please see the followings: ************************************************** ******* Links: 1 - This document describes how to create a Visual Basic application using the Crystal Report Designer Component 9 (RDC). This document covers the basic properties and methods that would be used to create an application that prints, previews, or exports a report. This document is for use with Crystal Reports 9. Business Objects Online Support 2 - This document describes the new Report Designer Component properties and methods available at runtime to connect your report to its data source. This document is for use with Crystal Reports 9 and later. Business Objects Online Support 3 - This document describes the methods for creating a deployment package to distribute a Report Designer Component (RDC) 9 application. This document is for use with Crystal Reports 9. Business Objects Online Support 4 - This file contains a help file for developers using the Report Designer Component (RDC). This utility allows you to navigate through the object hierarchy of the RDC using an 'Explorer tree' type interface. Included are descriptions and/or syntax of objects, collections, methods, and properties. Business Objects Online Support ------------------------------------------------------------------------------------ How to make a database connection using the Report Designer Component 9 The information in the article refers to: Report Designer Component 9 Applies to: Reported version only Logon and RDC ConnectionProperties Synopsis An application uses the Report Designer Component (RDC) 9 as the reporting development tool. Earlier versions of the Report Designer component used the 'SetLogonInfo' method to log on to the database in the main and subreport. When using RDC in Crystal Reports 9, what is the recommended method to log on to a database? Solution When using the Report Designer Component (RDC), the recommended method to log on to a database in Crystal Reports 9 is the 'ConnectionProperties' method. The 'ConnectionProperty' method has different properties depending on what type of connection you use in the report. ==================== NOTE: To check what type of connection you are using: 1. In the Crystal Reports Designer, go to the Database > Set Datasource Location menu. 2. In the 'Current Data Source' dialog box, expand the 'Properties' node. ==================== For a native connection to an Access database, use the following code sample ---------------------------------------------------------------------------------------------- Dim crxDatabaseTable As CRAXDRT.DatabaseTable For Each crxDatabaseTable In Report.Database.Tables crxDatabaseTable.ConnectionProperties.Item("Databa se Name") = "C:\Temp\xtreme.mdb" Next crxDatabaseTable For an ODBC Connection, use the following code sample -------------------------------------------------------------------- With External_Report.Database.Tables(1).ConnectionPrope rties .Item("DSN") = "DSNname" .Item("Database") = "DBName" .Item("User ID") = "UID" .Item("Password") = "PWD" End With For an OLE DB Connection, use the following code sample ---------------------------------------------------------------------- With Report.Database.Tables(1).ConnectionProperties .Item("Provider") = "Provider Name" .Item("Data source") = "Server Name" .Item("Initial Catalog") = "Database Name" .Item("User ID") = "UID" .Item("Password") = "PWD" End With To set the path for an MDW file for an Access Secured Database using System Database Path ----------------------------------------------------------------------------------------------------------------- Report.Database.Tables(1).ConnectionProperties.Ite m("Session UserID") = "vantech" Report.Database.Tables(1).ConnectionProperties.Ite m("Session Password") = "vantech" Report.Database.Tables(1).ConnectionProperties.Ite m("System Database Path") = "\\vanfps12\clo$\session level security\Secured.mdw" ==================== NOTE: For further information about the 'ConnectionProperties' method go to Business Objects Online Support and search for: cr_rdc9_connectionproperties.pdf ==================== Hope it will help for u, LwinAung Last edited by lwinaung : 07-17-2008 at 03:54 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |