Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening form by function call - PROBLEMS! 7

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
584
GB

I have several forms which I need to pass criteria to when opening.


Rather than using the docmd.... I have a function in the form which I call and this results in the form opening.

Doing this lets me pass multiple criteria to the form when it opens.

The code in the form is like...

Form_frm_Email.fnc_SetUpForm SetForm_Title:="Email To Landord: " & Me.Lan_1_Name_Long, _
SetAddress_To:=Me.Lan_1_Email, _ etc...

To Open the form from another using a button I use:

Public Sub fnc_SetUpForm(ByVal SetAddress_To As Variant, _
Optional ByVal SetAddress_CC As Variant = Null etc....

This all works fine, BUT I have the following problem...

When opening the form (although it is set as Modal and Popup), the code from the open button continues to execute, rather than halting when the form opens.

I also note that when the form is opened by using the function, there is no design view avaiable (although if i just open the form norally design view is avalable).

I would very much appreciate thoughts about what is different when the form is opened through a function and also if there is away I can get the code to stop running on opening, but still retain the method of opening the form by calling the funstcion.

Many thanks Mark
 
Sorry I mixed up the two bits of code

To open the form my button click event has...


Form_frm_Email.fnc_SetUpForm
And then the functions parameters.

As the function, fnc_SetUpForm is in the form frm_email,
This makes access open the form.

Thank you Mark.
 
dhookom wants to see the whole code you have in this Sub (what you call a Function):

Code:
Public Sub fnc_SetUpForm(ByVal SetAddress_To As Variant, _
 Optional ByVal SetAddress_CC As Variant = Null etc....
[green]
''''????
[/green]
End Sub

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Hi guys....

From Button click event......

Code:
Form_frm_Email_Flexible.fnc_SetUpForm SetForm_Title:="Email To Landord: " & Me.Lan_1_Name_Long, _
                                        SetAddress_To:=Me.Lan_1_Email, _
                                        SetAddress_CC:=IIf(Me.chk_Lan_1_Email_CCLan2, Me.Lan_2_Email, Null), _
                                        SetAddress_BCC:=Null, _
                                        SetSubject:=Null, _
                                        SetBody:=Null

Public sub on form....

Code:
Public Sub fnc_SetUpForm(ByVal SetAddress_To As Variant, _
                Optional ByVal SetAddress_CC As Variant = Null, _
                Optional ByVal SetAddress_BCC As Variant = Null, _
                Optional ByVal SetAddress_AllowEdit As Boolean = False, _
                Optional ByVal SetSubject As Variant = Null, _
                Optional ByVal SetBody As Variant = Null


Thank you Mark
 
Let me clarify:

I am calling the function which is a public function in the form code. So calling this makes the form open but not visible.

I then set the form to visible at the end of my function, once I have set up the form..

I do this because I want to set multi values in the modal popup form from the calling form before it is displayed. OpenArgs is not good enough as I have many values and parsing this would be problematic.

Open Code in Modal Form:
Code:
Public Sub fnc_SetUpForm(ByVal SetAddress_To As Variant, _
 Optional ByVal SetAddress_CC As Variant = Null etc....

'setup form using parameter values etc...

me.Visible = true  'Makes the form visible

End Sub

 
I still don't see any line of code that begins with DoCmd.OpenForm.

You can use a little code to embed anything/everything you want in openargs.

Code:
Public Function ParseAttrib(strText As String, _
        strAttrib As String, _
        strDelimiter As String)
'---------------------------------------------------------
' Procedure : ParseAttrib
' Author    : Duane Hookom
' Date      : 10/1/2010
' Purpose   : Pull a single value from a multi-value string
'             the strText must use = to match an attribute with its value
'
' Samples
' --------------------------------------------------------
' ParseAttrib("color=red;Age=50;Dog=False","Color",";")=red
' ParseAttrib("color=red;Age=50;Dog=False","dog",";")=False
'---------------------------------------------------------
    Dim arText() As String
    Dim intI As Integer
    On Error GoTo ParseAttrib_Error

    arText() = Split(strText, strDelimiter)
    For intI = 0 To UBound(arText)
        If Split(arText(intI), "=")(0) = strAttrib Then
            ParseAttrib = Split(arText(intI), "=")(1)
        End If
    Next

    On Error GoTo 0
    Exit Function

ParseAttrib_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ParseAttrib of Module basParseText"

End Function

Duane
Hook'D on Access
MS Access MVP
 
@moss100, in your function, fnc_SetUpForm(), Duane expects to see DoCmd.OpenForm ...

That's what he's asking. He wants you to post THE ENTIRE FUNCTION.

You claim that "the code from the open button continues to execute, rather than halting when the form opens." Well he wants to see what code it is that is being executed in this function.

You have asked a question, but then refuse to supply the information necessary to provide a cogent answer.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I am not using the docmd open - the form opens when the me.visible = true part of the function is reached.

I am unable to pass a recordset if I use the openargs.

Thanks Mark

 
Hello - yes the full code is below:


Form_frm_Email_Flexible.fnc_SetUpForm SetForm_Title:="Email To Landord: " & Me.Lan_1_Name_Long, _
SetAddress_To:=Me.Lan_1_Email, _
SetAddress_CC:=IIf(Me.chk_Lan_1_Email_CCLan2, Me.Lan_2_Email, Null), _
SetAddress_BCC:=Null, _
SetSubject:=Null, _
SetBody:=Null

me.refresh


It is the me.refresh that I wish to run after the form closes.
 
I guess we will never know what's the code between:

[tt]Public Sub fnc_SetUpForm([/tt]
and
[tt]End Sub [/tt]

Top secret...[ponder]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
It's like pulling hens' teeth!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Sorry I was not trying to be awkward - just the opposite.

Here is the code from the form with my open button:

Code:
Form_frm_Email_Flexible.fnc_SetUpForm SetAddress_To:=Me.Lan_1_Email, _
                                        SetAddress_CC:=IIf(Me.chk_Lan_1_Email_CCLan2, Me.Lan_2_Email, Null), _
                                        SetAddress_BCC:=Null, _
                                        SetSubject:=Null, _
                                        SetBody:=Null



Here is the code from the form I am opening

Code:
'Use to open form
Public Sub fnc_SetUpForm(ByVal SetAddress_To As Variant, _
                Optional ByVal SetAddress_CC As Variant = Null, _
                Optional ByVal SetAddress_BCC As Variant = Null, _
                Optional ByVal SetAddress_AllowEdit As Boolean = False, _
                Optional ByVal SetSubject As Variant = Null, _
                Optional ByVal SetBody As Variant = Null)

  ' Sets the forms textboxes for basic information

  Me.txt_Email_To = SetAddress_To
  Me.txt_Email_CC = SetAddress_CC
  Me.txt_Email_BCC = SetAddress_BCC
  Me.txt_Email_Subject = SetSubject
  Me.txt_Email_Body = SetBody
  
  'Set enable state of To address
  Me.txt_Email_To.Enabled = SetAddress_AllowEdit

  'Make form visible
  Me.Visible = True

End Sub
 
The above code covers the opening of the form - there is NO Docmd.OpenForm used.

Thank you Mark
 
Or if you create a blank database with two forms:

On the first form I have a button set to open form 2. The code on the button is:

Code:
Private Sub Command0_Click()

Form_frmTwo.fnc_SetUpForm SetTitle:="Hello"

End Sub

The code in the second form is:

Code:
Public Sub fnc_SetUpForm(ByVal SetTitle As Variant)

Me.TITLE = SetTitle

Me.Visible = True
End Sub

I hope that helps get my method across. Thank you all Mark
 
You didn't think to tell us these forms were class objects. I've never used them since standard forms have always done what I needed them to do including "halting when the form opens".

Duane
Hook'D on Access
MS Access MVP
 
Not sure I understand that comment, Duane. Standard Access forms are class objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top