Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 771
  • Last Modified:

About vb6.0 report

hello experts,
How to place a control (like command box) in data report in VB 6.0?
0
Thilak
Asked:
Thilak
  • 7
  • 3
1 Solution
 
Ryan ChongCommented:
You can't do that, the data report not supported that.
0
 
ThilakAuthor Commented:
ryancys,
 thanks for ur response.
is it possible to place a data report on the form?
and how to remove the default print and remove button from
the data report?
if possible plz explain me.

Thank u.
0
 
Ryan ChongCommented:
Not try this before, but you can try it by using the SetParent API. First try get the Handle of Form as Parent Hwnd and get the Handle of Report as Child Hwnd.

Probably will be like this:

Public Declare Function SetParent Lib "user32" _
   (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

SetParent rpt.hwnd, frm.hwnd

May try this at home.

regards
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Ryan ChongCommented:
What do you want to do within the Button's Action?

Here is an alternative. Why do you show the Button (a form includes the Button) first, select the details, then generate a report regarding what is selected from the form.

regards
0
 
ThilakAuthor Commented:
hello ryancys,
  thanks for ur suggestion. i want to select the font first
and it should reflect in the report accordingly. i have
created a font dialog box but it doesn't make a change.

Thank u.
0
 
Ryan ChongCommented:
So you mean a way to change the Data Report's font?

If it's i will try to see if this can be achieve or not.

regards
0
 
Ryan ChongCommented:
Hi Thilak,

Actually we can add a comman button to a Data Report like this:

Dim t As Object 'Or t As VB.CommandButton
Set t = Controls.add("VB.CommandButton", "Command1")

Then set the parent of t Object to the Data Report. I tried this method already and it's working. But i think the better approach is create a form, then set the form's parent to Data Report.

Here is the solution i have tested:

First, we need 2 forms (Form1 and Form2), 1 Data Report (DataReport1), 1 Data Environment (Which is the connection of Data Report). Form1 is the form that replace the standard toolbar of the Data Report, while Form2 is the form to call Data Report, that mean we run Form2 rather than Form1.

Here is the code of Form1:

Controls needed: 2 combobox (Combo1, Combo2), 2 checkboxes (Check1, Check2), 3 commandbuttons (Command1, Command2, Command3)
<Note>: Remove Command2 and Command3 if you don't want the Print and Export buttons.
---------------------------
Private Sub Combo2_Change()
    Combo2.Text = Trim$(Combo2.Text)
    If IsNumeric(Combo2.Text) Then
        Combo2.Tag = Combo2.Text
    Else
        Combo2.Text = Combo2.Tag
    End If
End Sub

Private Sub Command1_Click()
    If Combo1.Text = "" Or Combo2.Text = "" Then Exit Sub
    If Not DataReport1 Is Nothing Then
        For i = 1 To DataReport1.Sections("Section1").Controls.Count
            DataReport1.Sections("Section1").Controls(i).Font.Name = Combo1.Text
            DataReport1.Sections("Section1").Controls(i).Font.Size = IIf(Val(Combo2.Text) < 8, DataReport1.Sections("Section1").Controls(i).Font.Size, Val(Combo2.Text))
            DataReport1.Sections("Section1").Controls(i).Font.Bold = Check1.Value
            DataReport1.Sections("Section1").Controls(i).Font.Italic = Check2.Value
        Next i
        DataReport1.Refresh
    End If
End Sub

Private Sub Command2_Click()
    DataReport1.PrintReport True
End Sub

Private Sub Command3_Click()
    DataReport1.ExportReport
End Sub

Private Sub Form_Load()
    'Set the Combo1, Combo2's Style to 2
    'Set the form's ControlBox Property to False
    'Set the form's BorderStyle Property to FixedSingle
   
    'Command1 will be the Set Font Button
    'Command2 will be the Print Button
    'Command3 will be the Export Button
    'Check1 will let text to be Bold
    'Check2 will let text to be Italic
    'Set the Check1's Style to Graphical
    'Set the Check2's Style to Graphical
   
    Form1.Caption = ""
    Form1.BorderStyle = vbFixedSingle
   
    Command1.Height = 315
    Command1.Caption = "Set Font"
    Command2.Height = 315
    Command2.Caption = "Print"
    Command3.Height = 315
    Command3.Caption = "Export"
   
    Check1.Height = 315
    Check2.Height = 315
    Check1.Caption = "B"
    Check1.FontBold = True
    Check2.Caption = "I"
    Check2.FontItalic = True
   
    Form1.ScaleMode = vbPixels
   
    LoadSystemFonts Combo1
    Combo2.AddItem "9"
    Combo2.AddItem "10"
    Combo2.AddItem "11"
    Combo2.AddItem "12"
    Combo2.AddItem "14"
    Combo2.AddItem "16"
    Combo2.AddItem "18"
    Combo2.AddItem "20"
   
    loadCurrentSetting
   
End Sub

Private Sub loadCurrentSetting()
    On Error Resume Next
    If Not DataReport1 Is Nothing Then
        If DataReport1.Sections("Section1").Controls.Count > 0 Then
            Combo1.Text = DataReport1.Sections("Section1").Controls(1).Font.Name
            Combo2.Text = DataReport1.Sections("Section1").Controls(1).Font.Size
            Check1.Value = DataReport1.Sections("Section1").Controls(1).Font.Bold
            Check2.Value = DataReport1.Sections("Section1").Controls(1).Font.Italic
        Else
            Combo1.Text = "Arial"
            Combo2.Text = "10"
            Check1.Value = 0
            Check2.Value = 0
        End If
        Combo2.Tag = Combo2.Text
    End If
End Sub
---------------------------

Here is the code of Form2:
Controls needed: 1 commandbutton (Command1)
---------------------------
Private Sub Command1_Click()
    DataReport1.Show
    Form1.Show
    SetParent Form1.hWnd, DataReport1.hWnd
End Sub

Private Sub Form_Load()
    Command1.Caption = "Show Report1"
End Sub
---------------------------

Here is the code of DataReport1
<Note:> Make sure you have a section called "Section1", the Form1's Size depends on how you draw the controls at form.
---------------------------
Private Sub DataReport_Activate()
    DataReport_Resize
End Sub

Private Sub DataReport_Resize()
   
    Form1.Height = 450
    Form1.ScaleTop = DataReport1.Top
   
    Form1.ScaleWidth = 8200
    Form1.ScaleLeft = DataReport1.Width - Form1.ScaleWidth + 5000
End Sub

Private Sub DataReport_Terminate()
    Unload Form1
End Sub
---------------------------

and finally a Module which includes codes below:
---------------------------
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Public Sub LoadSystemFonts(ByRef myControl As Object)
    On Error Resume Next
    myControl.Clear
    Dim i As Long
    For i = 0 To Screen.FontCount - 1
        myControl.AddItem Screen.Fonts(i)
    Next i
End Sub
---------------------------

Try run the code start from Form2 and see how the result goes. Of course, customize the code above to reach your requirement.

Cheers,
ryancys
0
 
Ryan ChongCommented:
Hi Thilak,

Sorry! The code posted about not working quite well when we resize the Data Report, here we need to change the code above a bit as follows:

1. Add this code at the Form_Load Event of Form1:

'Set the form's size once so that we don't need to change the size again in DataReport1
Form1.Height = 450
Form1.Width = 9650
Form1.Left = 0
Form1.Top = 0

2. Then remove ALL the code in DataReport1 to:

Private Sub DataReport_Terminate()
    Unload Form1
End Sub

Cheers,
ryancys
0
 
ThilakAuthor Commented:
hai ryancas,
    Thank u very much. your pgm is simply superb. you have given me what i was searching and expecting for such a long period.

with luv,
Thilak.
0
 
Ryan ChongCommented:
Glad could make helps, thanks for grade 'A' :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now