What are you trying to return? Could you use a global variable and assign a value to it from the form? Any details? If you choose to battle wits with the witless be prepared to lose.
I've been working with forms for a while and I don't have a 'style' developed yet. I keep thinking there must be something more than just accessing global variables.
You know how you can get the return value of msgbox.
Code:
if msgbox("Press Yes for msg.",vbYesNo) = vbYes then
msbbox(msg)
end if
Is thare a way of making a user defined form act the same.
Eg. A form that u Select a # from 1-10. and the form return the results. Brawn
- The difference between genius and stupidity is that genius has its limits -
The only way I can think, is to create a function that handles the form and returns the value.
Code:
public function getNumber()as integer
dim returnValue as integer
frmGetNumber.Show
returnvalue = frmGetNumber.gm_intSelecteNumber
frmGetNumber.Hide
getNumber = returnValue
End function
...or something of the like. Brawn
- The difference between genius and stupidity is that genius has its limits -
A form is basically just a visual class, so - with a few restrictions - you can do much the same as with a class. The following (slightly contrived) example illustrates the use of both a public function and of a property get to return values from a form.
First create a form (Form1) with a command button on it, and drop in the following code: [tt]
Option Explicit
Private Sub Command1_Click()
MsgBox Form2.myMsg("Click Command1 or Command2", , "From Form Function"
Unload Form2 ' Deliberately unload the form here to demonstrate that property survives this
MsgBox Form2.ExitCode, , "From Form Property"
End Sub [/tt]
Now create a second form (Form2) with a label and two command buttons. Then drop in the following code: [tt]
Option Explicit
Private mvarDemo As Long
Private Sub Command1_Click()
mvarDemo = vbOK
CloseMe
End Sub
Private Sub Command2_Click()
mvarDemo = vbCancel
CloseMe
End Sub
Public Function myMsg(strMessage As String) As Variant
Me.Label1 = strMessage
Me.Show vbModal
myMsg = mvarDemo
End Function
Private Sub CloseMe()
Me.Hide
End Sub
Public Property Get ExitCode() As Long
ExitCode = mvarDemo
End Property
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.