By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,105 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,105 IT Pros & Developers. It's quick & easy.

Pass a string get a form

P: n/a
Whew, it's been a while since I posted. Fogive me all for I have...

anyway.

I would like to be able to write a method of an object that could
accept a string and set the corresponding form. It an easy thing to
do if I am talking about a recordset. I could simply loop through the
recordset collection, find the one that I wanted, and then set my
object to the one that I found.

But forms are seemingly different. The code out there demands that a
form either be open or in design view. That would totally defeat the
point of what I am trying to do. From what I find in help, if I want
to loop through all of the forms open or not I have to go through the
documents collection. That is fine, but when I find the form I want,
I am still left with a string variable that I want to set to a form,
and that just won't work. You need a text literal to set an object to
as far as I know.

Public frmName as form
Public sub setThatForm(StrFormName)
WHAT GOES HERE?

end sub
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
If you want to do something like DoCmd.OpenForm... for a certain
condition, looping through the document collection may not work since I
believe the form has to be already up and running (for which
DoCmd.OpenFormm... would not be an issue). But if this is something you
had in mind, you could hardcode the list of forms in your DB into an
array (variant array) or list them in a table. If you just want to
access a running form, then looping through the document collection
should get all the open forms. If you want to pass a form object to a
procedure try this:

Sub frm1()
Dim frm As Form
Set frm = Forms!frm2
Call Procfrms(frm)
End Sub

Sub Procfrms(f As Form)
Dim str1 As String
str1 = frm!List1.Column(0)
...
End Sub

Or something like that (of course, in this example it would be easier to
pass whatever was selected in the listbox (List1)). Or maybe you want
to pass the form object to a class object to disable all the controls on
the form while a procedure is running.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.