Solved

About vb6.0 report

Posted on 2002-07-14
10
742 Views
Last Modified: 2007-12-19
hello experts,
How to place a control (like command box) in data report in VB 6.0?
0
Comment
Question by:Thilak
  • 7
  • 3
10 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7152266
You can't do that, the data report not supported that.
0
 

Author Comment

by:Thilak
ID: 7153700
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7153718
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7153725
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
 

Author Comment

by:Thilak
ID: 7154272
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7158840
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7161597
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
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 30 total points
ID: 7164219
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
 

Author Comment

by:Thilak
ID: 7164422
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7168871
Glad could make helps, thanks for grade 'A' :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now