-
Aug 28th, 2014, 02:07 AM
#1
[RESOLVED] Pass Form Reference to another Form
My question is 'How to set a reference to a Form' using (I guess) Property Set
I am exploring some examples for a grid control (iGrid)
Their main examples do not demonstrate direct printing, however one of their extra small samples does have code for that.
I am now trying to blend that functionality into their main demo.
That entails adding a bas file and a wee form frmPrinterSelection. (frmPrinterSelection is the form that then calls/executes the bas code)
I would like to make that code more 'black box' (self contained).
Currently the wee form refers to the calling Form by name.
I would prefer that the calling Form passes (SETs) a reference to the Form.
frmMain which contains the grid, will set a Reference to itself in frmPrinterSelection, and then show frmPrinterSelection
I am pretty sure that what I need is a Proprty Set
I have led a simple VB6 life, (avoiding classes, etc).
Also I don't recall ever coding a Property Set
Could someone assist me with this 'black boxing'
Rob
Here is the sample (not 'black boxed' yet)iGridPrint_Trimmed.zip
-
Aug 28th, 2014, 03:30 AM
#2
Re: Pass Form Reference to another Form
Code like this in Form1;
Code:
Private Sub Command1_Click()
Set Form2.CallingForm = Me
Form2.Show vbModal
End Sub
Public Sub MyPrintRoutine(PrintDevice As Object)
PrintDevice.Print "The Report"
PrintDevice.Print
PrintDevice.Print
PrintDevice.Print
If TypeOf PrintDevice Is Printer Then PrintDevice.EndDoc
End Sub
Code like this in Form2
Code:
Dim mFm As Form
Public Property Set CallingForm(Fm As Form)
Set mFm = Fm
End Property
Private Sub Command1_Click()
'you can access Public Properties and Methods on the Calling Form using the mFm reference
mFm.BackColor = vbRed
mFm.MyPrintRoutine Me ' or mFm.MyPrintRoutine MySelectedPrinterObject
End Sub
-
Aug 28th, 2014, 04:20 AM
#3
Re: Pass Form Reference to another Form
My code above solves the Form reference but still ties you to using a Public Method named 'MyPrintRoutine'; to avoid that.
Code in Form1
Code:
Private Sub Command1_Click()
Form2.SetCallBack Me,"MyPrintRoutine"
Form2.Show vbModal
End Sub
Public Sub MyPrintRoutine(PrintDevice As Object)
PrintDevice.Print "The Report"
PrintDevice.Print
PrintDevice.Print
PrintDevice.Print
If TypeOf PrintDevice Is Printer Then PrintDevice.EndDoc
End Sub
'Code in Form2
Code:
Private Type Cbn
Obj As Object
funct As String
End Type
Dim CbnObject As Cbn
Public Sub SetCallBack(Obj As Object, funct As String)
Set CbnObject.Obj = Obj
CbnObject.funct = funct
End Sub
Private Sub Command1_Click()
CallByName CbnObject.Obj, CbnObject.funct, VbMethod, SelectedPrintObject
End Sub
-
Aug 28th, 2014, 10:49 PM
#4
Re: Pass Form Reference to another Form
Thank you, Magic Ink,
I appreciate you taking the time and trouble to assist me.
Regards,
Rob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|