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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Global Module/Passing Variables question

Status
Not open for further replies.

delman333

Technical User
Oct 20, 2003
32
US
OK...building on previous suggestions I was able to make some of my global modules work fine...especially after learning to pass forms as Forms instead of strings. However, although the first part of my routine below works by passing OldForm as a Form, I cannot figure out how to make the two highlighted areas work using the OldForm and NewForm. I can only make it work using strings...or by typing them in directly (which defeats the purpose of the global module). In other words...if I pass OldForm and NewForm as Forms...the top part works. If I pass them as Strings the bottom part works. What can I do to make both work?

Public Sub GoToOtherForm(NewForm As Form, FormID As String, FormFocus As String, OldForm As Form, CheckField As Control)

Call GoToOtherFormMessageBox

If MessageBox = vbCancel Then
DoCmd.GoToControl (strLastFocus)
Else
If MessageBox = vbOK Then
Call OrdnanceClearActiveItem
If CheckField.Enabled = True Then
OldForm.ClearFormButton.Enabled = False
OldForm.ClearActiveItemButton.Enabled = False
ElseIf CheckField.Enabled = False Then
OldForm.ClearFormButton.Enabled = True
OldForm.ClearActiveItemButton.Enabled = False
End If
DoCmd.OpenForm "ScenarioOverviewForm", , , , acFormEdit, , strScenario_ID
DoCmd.GoToControl (FormID)
DoCmd.FindRecord strScenarioID, , True, , True, , True
DoCmd.GoToControl (FormFocus)
AllowClose = True
DoCmd.Close acForm, "ScenarioOrdnanceForm"
End If
End If

End Sub
 
Hi again!

Have you tried the .Name property of your form variables?

[tt]docmd.close acform OldForm.Name[/tt]

(if this works, you've given me more than enough pinkies, and thank you very much for that!)

Roy-Vidar
 
...and of course forgot a comma, but you'd figgered that out;-)

[tt]docmd.close acform, OldForm.Name[/tt]
 
OK...one step closer. Using OldForm.Name did the trick for that part. However...still one problem left.

Here is the Private Sub calling the Global Module Public Sub:

Call GoToOtherForm(Forms!ScenarioOverviewForm, "ScenarioID", "EnterOverviewButton", Forms!ScenarioOrdnanceForm, P01)


I get the "can't find the form ScenarioOverviewForm" error.

If I change it to this:

Call GoToOtherForm(ScenarioOverviewForm, "ScenarioID", "EnterOverviewButton", Forms!ScenarioOrdnanceForm, P01)

I get a Variable not defined error.

If a put a Public Variable like this into the code:

Public ScenarioOverviewForm As Form

It works provided I still enter the name as a String into the called Public Sub as mentioned in my first post.

If I change the string to NewForm.Name I get:

Object variable or With block not set.

I'm starting to go a little bonkers on this one......ahhhhhhhhhhhh.

Ok...I feel better now. Any more suggestions?
 
he he - there was a reason I choose the your OldForm in the example;-)

I was a bit concerned about the NewForm being open or not, but I was reasonable sure your OldForm was. I'm not 100% sure, but I think form references only work with open forms. I e:

[tt]set frm=forms!someform[/tt]

Gives the error you mention, if the form is closed.

- could it be an alternative for you to just hide and show the forms (using the visible property)

Roy-Vidar
 
...perhaps not very kind of me not to mention it, but, honestly, didn't think of it at the time, just copy/pasted the line nearest to the reply window;-)

But having a routine to close and open, where you only specify the form to open, isn't too bad, is it?

[tt]Call GoToOtherForm("ScenarioOverviewForm", "ScenarioID", "EnterOverviewButton", Forms!ScenarioOrdnanceForm, P01)

Public Sub GoToOtherForm(NewForm As String...

docmd.openform newform,...[/tt]
 
Very cool Roy. That's exactly what I decided to do since I only need the NewForm reference in that one place. All the other things I needed to do with the passed forms involved the OldForm and that worked fine passing it as a Form. Of course that was after I used the .Name hint you gave me.

Now...if you feel like helping to accelerate my learning curve some more...if I were to pass the OldForm as a string...what changes would I have to make to the Public Sub to make it work? Just curious...for future reference.

Anyway...thanks a lot...you've given me some great advice the last couple of months.
 
Hi again, and thank you for the very kind words!

Assuming the name is passed as the String OldForm and ClearFormButton and ClearActiveItemButton are actual control names.

Considering the part of code regarding the oldform, something like this perhaps?

[tt]If CheckField.Enabled = True Then
forms(OldForm)("ClearFormButton").Enabled = False
forms(OldForm)("ClearActiveItemButton").Enabled = False...[/tt]

Or to use the complete references

[tt]If CheckField.Enabled = True Then
forms(OldForm).Controls("ClearFormButton").Enabled = False
forms(OldForm).Controls("ClearActiveItemButton").Enabled = False...[/tt]

and, given this opportunity, I simply can't resist rewriting your whole if elseif construct to:

[tt]forms(OldForm)("ClearFormButton").Enabled = Not CheckField.Enabled
forms(OldForm)("ClearActiveItemButton").Enabled = Not CheckField.Enabled[/tt]

- an "easy", and often recommended way of toggling booleans

;-)Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top