How to get the date parameter field in the CRViewer control? - vb6

Using VB 6 and Crystal Report 8.5
I want to pass the date parameter filed in CRViewer control.
Code:
Dim crApp As CRAXDRT.Application
Dim Report As CRAXDRT.Report
CR2.ParameterFields(1) = "txtFromDate;" & dtpFrom.Value & ";true"
CR2.ParameterFields(2) = "txtToDate;" & dtpTo.Value & ";true"
CR2.DataFiles(0) = App.Path & "\STAR.mdb"
CR2.ReportFileName = App.Path & "\MS.rpt"
Set crApp = New CRAXDRT.Application
Set Report = crApp.OpenReport(App.Path & "\MS.rpt")
CRViewer2.ReportSource = Report
CRViewer2.ViewReport
Parameterfield(1), Parameterfield(2) was not displaying in the crviewercontrol.
How to pass the date parameter field in the CRViewer control?
Need VB 6 code help.

To my understanding, you have to pass the date to the parameter field in the same format as CR is expecting. Open the report in Crystal Reports, and go to the Edit screen for each parameter field. Make sure the fields are of Date type instead of DateTime as it doesn't seem you need to account for time given your example. Then click on "Set Default Values", this screen will show you the format CR is expecting for the parameter (usually M/D/YYYY). In your code, format your date value to be passed to the parameter:
CR2.ParameterFields(1) = "txtFromDate;" & Format(dtpFrom.Value, "M/D/YYYY") & ";true"
CR2.ParameterFields(2) = "txtToDate;" & Format(dtpTo.Value, "M/D/YYYY") & ";true"
Edit: Or D/M/YYYY, just depends on what CR wants.

Related

vbscript to dynamically update the excel cell range,when source data is updated and refresh the pivot table simultaneously

I have an excel workbook consisting of a source data and a pivot table.
the source data gets updated with new records daily along with some changes in the existing data.
I have written a vbscript in notepad and saved it with .vbs and I am calling it from Rstudio to perform the refresh pivot table action.
But,when I run this script in Rstuido :
pathofvbscript = ("D:\\Users\\703225799\\WIP\\R\\pivot\\r5.vbs")
shell(shQuote(normalizePath(pathofvbscript)),"cscript",flag =
"//nologo")
I am getting the following error :
D:\Users\703225799\WIP\R\pivot\r5.vbs(14, 1) Microsoft VBScript runtime
error: Object doesn't support this property or method: 'objWB.Range'
VBS code :
'------------------------------------------------------------------------
'Set Pivot Table & Source Worksheet
'------------------------------------------------------------------------
Set objExcel = CreateObject("Excel.Application")
Set objWB =
objExcel.Workbooks.Open("D:\Users\703225799\WIP\R\pivot\New
folder\Book1.xlsx")
Set Pivot_Sheet = objWB.Worksheets("pvt")
'-----------------------------------------------------------------------
'Enter in Pivot Table Name
'-----------------------------------------------------------------------
PivotName = "PivotTable1"
objWB.Activate
Set StartPoint = objWB.Range("A1")
LastCol = StartPoint.End(xlToRight).Column
DownCell = StartPoint.End(xlDown).Row
Set DataRange = Data_Sheet.Range(StartPoint, Cells(DownCell, LastCol))
New_range = objWB.Name & "!" & DataRange.Address(xlR1C1)
Pivot_Sheet.PivotTables(PivotName). _
ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(xlDatabase,NewRange)
'----------------------------------------------------------------------
'Ensure Pivot Table is Refreshed
'----------------------------------------------------------------------
Pivot_Sheet.PivotTables(PivotName).RefreshTable
'Data_Sheet.Save
'MsgBox "Your Pivot Table is now saved."
'Data_Sheet.Close
'MsgBox "Your Pivot Table is now closed."
'objExcel.Quit
'MsgBox "objExcel quit."
'----------------------------------------------------------------------
'Complete Message
'----------------------------------------------------------------------
Pivot_Sheet.Activate
MsgBox "Your Pivot Table is now updated."
objWB.Save
objWB.Close
set objExcel = Nothing
set Data_Sheet = Nothing
Set Pivot_Sheet = Nothing
Please help with the error.
Thanks,
Sayan
Please try using Pivot_Sheet.Range("A1") instead of objWB.Range("A1") as the worksheet object is Pivot_sheet

Visual Basic Compare Files Task

I currently have this code that will compare between two files only if each file has one column:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("C:\Users\Downloads\Define Kickouts\Metadata_Account.txt", ForReading)
strCurrentDevices = objFile1.ReadAll
objFile1.Close
Set objFile2 = objFSO.OpenTextFile("C:\Users\Downloads\Define Kickouts\DataFile_Account.txt", ForReading)
Do Until objFile2.AtEndOfStream
strAddress = objFile2.ReadLine
If InStr(strCurrentDevices, strAddress) = 0 Then
strNotCurrent = strNotCurrent & strAddress & vbCrLf
End If
Loop
objFile2.Close
Wscript.Echo "Addresses without current devices: " & vbCrLf & strNotCurrent
Set objFile3 = objFSO.CreateTextFile("C:\Users\Downloads\Define Kickouts\Differences.txt")
objFile3.WriteLine strNotCurrent
objFile3.Close
However, I'm trying to figure out a way to create the script where the user can define which columns in the date file to compare against the same set of metadata files.
For example, in the data file, if we want to compare Account, Entity, and Department members, in the script, we would type in columns 1, 4, 5 based on the position in the headers...
Account, Project, Practice, Entity, Department
GL1000,P5000,PP2000,USA,D120
GL2000,P6000,PP3000,CANADA,D220
Then, the script will compare 'always' against the first column in each metadata file...
Account.csv
First column sample values:
GL5000,blah,blah,blah
GL1000,blah,blah,blah
Entity.csv
First column sample values:
ASIA,blah,blah,blah
CANADA,blah,blah,blah
Department.csv
First column sample values:
D100,blah,blah,blah
D200,blah,blah,blah
The output file will have kick-outs from the data file that aren't in the metadata files for each column.
Account Kickout.txt
GL2000
Entity Kickout.txt
USA
Department Kickout.txt
D120
D220
Any help would be appreciated!

Populate and sort a ComboBox from another ComboBox, VBA

Hi Everyone I am having trouble getting a ComboBox to sort, when another combobox is selected.
I think I have the Right SQL Syntax but I cant seem to get the vba to run it through; currently the vba returns all of the states in the recordset regardless of the company.
Private Sub CboCountry_Click()
Set db = CurrentDb
Dim SQLStr As String
Set RsState = db.OpenRecordset("T2States", dbOpenSnapshot, dbSeeChanges)
'populates combobox with recordset, that is defined by the country input from the form
RsState.MoveFirst
Do While Not RsState.EOF
Me.CboState.RowSource = Me.CboState.RowSource & RsState("StateID") & ";" & RsState("State") & ";"
RsState.MoveNext
Loop
I think this is the right SQL String but I'm having trouble to get it to work.
'SQLStr = "SELECT T2States.StateID, T2States.States, T2States.CountryID" & _
" FROM T2States GROUP BY T2States.StatesID" & _
" WHERE T2States.CountryID = """ & Me.CboCountry.Value & """"
Any help will be greatly appreciated.
Edit#1
See Full Code below, the error that pops up when I substitute SQLStr into the Openrecordset is a Run-time error '3078' the microsoft access database engine cannot find the input table or query 'SQLStr'. Make sure it exists and that its name is spelled correctly.
What should happen is when a country is selected from CboCountry combobox, it will load the CboState combobox by sorting the recordset by CountryID
see below for both code parts
Private Sub Form_Load()
Set db = CurrentDb
Set RsCompany = db.OpenRecordset("T1Company", dbOpenDynaset, dbSeeChanges)
Set RsCountry = db.OpenRecordset("T2Countries", dbOpenSnapshot, dbSeeChanges)
Set RsAddress = db.OpenRecordset("T1Addresses", dbOpenDynaset, dbSeeChanges)
Set RsAddressType = db.OpenRecordset("T2AddressType", dbOpenSnapshot, dbSeeChanges)
Set RsCompanyAddress = db.OpenRecordset("T3Company_Address", dbOpenDynaset, dbSeeChanges)
Me.CboCountry = Null
Me.TxtAddress1 = Null
Me.TxtAddress2 = Null
Me.TxtAddress3 = Null
Me.TxtCity = Null
Me.CboAddressType = Null
Me.CboCountry = Null
Me.CboState = Null
Me.TxtPostalCode = Null
Me.TxtCompanyID = Null
Me.TxtLegalName = Null
Me.TxtNickname = Null
Me.TxtAddressID = Null
RsCountry.MoveFirst
Do While Not RsCountry.EOF
Me.CboCountry.RowSource = Me.CboCountry.RowSource & RsCountry("CountryID") & ";" & RsCountry("Country") & ";"
RsCountry.MoveNext
Loop
RsAddressType.MoveFirst
Do While Not RsAddressType.EOF
Me.CboAddressType.RowSource = Me.CboAddressType.RowSource & RsAddressType("AddressTypeID") & ";" & RsAddressType("AddressType") & ";"
RsAddressType.MoveNext
Loop
Me.TxtLegalName.SetFocus
End Sub
Private Sub CboCountry_Click()
Set db = CurrentDb
Dim SQLStr As String
'SQLStr = "SELECT T2States.StateID, T2States.State, T2States.CountryID" & _
" FROM T2States" & _
" WHERE T2States.CountryID = """ & Me.CboCountry.Value & """"
Set RsState = db.OpenRecordset("T2States", dbOpenDynaset, dbSeeChanges)
'populates combobox with recordset, that is defined by the country input from the form
RsState.MoveFirst
Do While Not RsState.EOF
Me.CboState.RowSource = Me.CboState.RowSource & RsState("StateID") & ";" & RsState("State") & ";"
RsState.MoveNext
Loop
End Sub
Let us see
1- sure you've to append with
Having T2States.States, T2States.CountryID
2- Error exist in it, extra 's' in the Column name:
GROUP BY T2States.StatesID
3- put all the code and i'll check with you what you miss.
best regards
This one turned out to be a quick fix in the Property Sheet under the DATA tab, the Row Source Type had to be changed back to 'Table/Query' from a 'Value'.
There is VBA that could account for this but it was just a simple as changing that Row Source.
The Reason for the mix up, for a quick bit of background if it helps, is that all my combo boxes are unbound and I was binding them with VBA Recordsets so the rowsource has to be a value list - Essentially the VBA is writing the list everytime it loads.
Where as when I started using SQL to generate the recordset, even though it was in VBA I had to change the property back to Table/Query.
Thanks.

CurrentRegion.Select and Table format in VBS

I'm very new (1 week) to visual basic and basically I'm trying to automate some repetitive work, now to the point , within a number of files produced with varying data I need to format the selected range as a table (medium 9) but i'm in a block at the moment and need some help and would really appreciate it, here is what i have so far>>>>
Option Explicit
Dim strDate, strRepDate, strPath, strPathRaw , strDate2
dim dteTemp, dteDay, dteMth, dteYear, newDate, myDate
myDate = Date()
dteTemp = DateAdd("D", -1, myDate)
dteDay = DatePart("D", dteTemp)
dteMth = DatePart("M", dteTemp)
dteYear = DatePart("YYYY", dteTemp)
If (Len(dteDay) = 1) Then dteDay = "0" & dteDay
If (Len(dteMth) = 1) Then dteMth = "0" & dteMth
strDate = dteYear&"-"&dteMth&"-"&dteDay
strDate2 = dteYear&""&dteMth&""&dteDay
Dim objXLApp, objXLWb, objXLWs
Set objXLApp = CreateObject("Excel.Application")
Set objXLWb = objXLApp.Workbooks.Open("C:\Users\CuRrY\Desktop\"&strDate2&"\Agent Daily Disposition "&strDate2&".xls")
objXLApp.Application.Visible = True
'start excell
Set objXLWs = objXLWb.Sheets(1)
'objXLWs.Cells(Row, Column ).Value
With objXLWs
objXLWs.Cells(3, 1).Value = "Agent Name"
'objXLWs.Range("A3").Select
objXLWs.Range("A3").CurrentRegion.Select
'End With
as you can see i reached as far as CurrentRegion.Select but how to format selected cells into (medium 9) i've tried so much and failed
Thanks for any help
You can configure the CurrentRegion(which represents a Range object) through the SpecialCells Submethod. Although your conditions are specific to your xls sheet, you will still have to follow the formatting available through the specialcells() method properties. Also, by utilizing the currentregion property, the page assumes you have a xls header. So it is important to verify your table structure before trying to incorporate this property.
For instance:
Sub FillIn()
Range("A1").CurrentRegion.SpecialCells(xlCellTypeBlanks).FormulaR1C1 _
= "=R[-1]C"
Range("A1").CurrentRegion.Value = Range("A1").CurrentRegion.Value
End Sub
View the available properties that can be applied to CurrentRegion -> Here
And the MSDN Article -> Here

get value of Checkbox in datagrid

I am working with windows application.
I have a datagrid in vb.net. Its first column is a checkbox. I want to know which checkboxes are checked and which are not.
My code is :
Dim dr As DataGridViewRow
For i = 0 To gdStudInfo.RowCount - 1
dr = gdStudInfo.Rows(i)
att = dr.Cells(0).Value.ToString()
If att.Equals("Present") Then
qry = "insert into Stu_Att_Detail values(" & id & "," & gdStudInfo.Rows(i).Cells(1).Value.ToString() & ",'" & dr.Cells(0).Value.ToString() & "')"
con.MyQuery(qry)
End If
Next
I am getting correct values for all checked check box, but it gets error when the checkbox is not checked.
What if you try this?
If Not String.IsNullOrEmpty(dr.Cells(0).Value) Then
'do stuff here
End If

Resources