Avatar of PeterRollinson
PeterRollinson
 asked on

Change WindowMode from acHidden to acDialog after opening it

I need to open a form as follows:
    stDocName = "PostCodeSearch"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
Make some change as follows:
    Forms.PostCodeSearch.PCArea = strSelectedText
    Forms.PostCodeSearch.Town = ""
    Forms.PostCodeSearch.Street.SetFocus

Then change its WindowsMode to acDialog so that the code in the calling module waits for the form 'PostCodeSearch' to close as if I had originally opened it acDialog.

Code being used
------------------------------------------------------------
Private Sub PCCearch_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "PostCodeSearch"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
If Nz(strSelectedText, "") <> "" Then  
    Forms.PostCodeSearch.PCArea = strSelectedText
    Forms.PostCodeSearch.Town = ""
    Forms.PostCodeSearch.Street.SetFocus
End If
Forms.PostCodeSearch.Visible = True
'Wait here for the 'PostCodeSearch' form to close and return control here
End Sub


Thanks
Microsoft Access

Avatar of undefined
Last Comment
Leigh Purvis

8/22/2022 - Mon
mpmccarthy

Forms("PostCodeSearch").Visible = True
ASKER CERTIFIED SOLUTION
Leigh Purvis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
PeterRollinson

ASKER
As I suspected, having tried on numerous occasion.

As this will probably be needed in various Forms, I suppose I'll have to use a Global variable, then the calling module will set it, the form 'PostCodeSearch' check the variable and after using the value if any clear it.

Does this sound as though it will be what I require?


'mpmccarthy' Yes but that does not make it dialog!


thanks

Peter
Leigh Purvis

Well the global variable was the first, easiest and most obvious solution.

Normally I'd use the form's Openargs to pass any information I wanted to the dialog form.
That way you can also determine which controls are to receive data (with just a little care in your string formatting).

Know the kind of thing?  Or need further details?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
PeterRollinson

ASKER
Hi LPurvis,

Yes I know the kind of thing, I too use it all the time with delimiters for various variable, but it can get a bit messy sometimes.

So i'm using the Global variable.

Anyhow thanks for the prompt replies.

Regards
Peter
Leigh Purvis

Well - it depends upon how you format and then extract items from your string.
If you have a couple of functions that do that for you then it's pretty clean (and something I'd always take over more globals cluttering up the application then necessary :-).

Whatever you feel most comfortable with though.

Glad to help.
PeterRollinson

ASKER
Hi LPurvis,

"if you have a couple of functions that do that for you then it's pretty clean"

Go on the enlighten me, it's bound to be better than mine :)


Regards

Peter
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Leigh Purvis

Umm - well the ones I use are from the Access Developer's Handbook (still the 97 version actually thinking about it lol)
(Not a big fan of posting code from books - these guys work hard and want people to buy their efforts after all :-)

OK then - a rough version of my own making.  Let's see.


Public Const cConcatDelim = "#~#"
Public Const cConcatOp = "~@~"

Function fAddStringPart(strConcat As String, strPartName As String, varValue) As String
   
    varValue = CStr(varValue)
    If Len(strConcat) = 0 Then strConcat = cConcatDelim
    If InStr(1, strConcat, cConcatDelim & strPartName & cConcatOp) = 0 Then
        fAddStringPart = strConcat & strPartName & cConcatOp & varValue & cConcatDelim
    End If
   
End Function

Function fGetStringPart(ByVal strConcat As String, strPartName As String)

    Dim strArr() As String
    Dim intI As Integer
   
    strConcat = Mid(strConcat, Len(cConcatDelim) + 1)
    strArr = Split(strConcat, cConcatDelim)
    For intI = 0 To UBound(strArr) - 1
        If Split(strArr(intI), cConcatOp)(0) = strPartName Then
            fGetStringPart = Split(strArr(intI), cConcatOp)(1)
            Exit Function
        End If
    Next
   
End Function



And you can see these in action

Sub TestConcatNow()
'Print extracted parts of a string

    Dim strTest As String
   
    strTest = fAddStringPart(strTest, "Text1", Date)
    strTest = fAddStringPart(strTest, "Text2", "Forename")
    strTest = fAddStringPart(strTest, "Text3", Now)
    strTest = fAddStringPart(strTest, "Text4", "Surname")
    strTest = fAddStringPart(strTest, "Text5", MonthName(Month(Date)))
   
    Debug.Print fGetStringPart(strTest, "Text2")  'Returns "Forename"
    Debug.Print fGetStringPart(strTest, "Text5")  'Returns "September"
   
End Sub

Sub InsertPassedOnly()
'Fill in controls by passed control names

    Dim strArgs
    Dim strArr() As String
    Dim intI As Integer
   
    strArgs = Nz(Me.OpenArgs)
    strArgs = Mid(strArgs, Len(cConcatDelim) + 1)
    strArr = Split(strArgs, cConcatDelim)
    For intI = 0 To UBound(strArr)
        Me(Split(strArr(intI), cConcatOp)(0)).value = Split(strArr(intI), cConcatOp)(1)
    Next
   
End Sub
PeterRollinson

ASKER
Ah yes well, took some getting my head arround but after following it through I see how it works.

Never come across the Split function before or for than matter the Ubound function.
Probably because I've never used arrays!

I'll have to do some more homework.

Thanks I'll use it when i fully understand these functions, now I have a headache :)

All the best

Peter
Leigh Purvis

No probs.

By way of an example - it is occasionally done that standard information is always passed to a new form.
But you always choose to ignore anything that isn't relevant in a particular case.
e.g.

strArgs = fAddStringPart(strTest, "Calling Form", Me.Name)
strArgs = fAddStringPart(strTest, "Passed ID", Me.PKField)
strArgs = fAddStringPart(strTest, "Show On Close", True)

Docmd.OpenForm "YourFormName", OpenArgs:=strArgs

It entirely up to you what you make use of in the form once it's opened.

When it opens (similar to stuff you'll have done before no doubt)
Me.Recordsource = "SELECT * FROM MyTable WHERE MyPKFIeld = " & fGetStringPart(strTest, "Passed ID")  

When it closes you could have code such as
If CBool(fGetStringPart(strTest, "Show On Close")) Then
    Forms(fGetStringPart(strTest, "Calling Form")).Visible = True
End If

Yadda yadda - you can go on and on ad infinitum.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy