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

Concentrating form name with string variable

100+
P: 176
Hi All.

Is it possible to concentrate
dim frm as Form
set frm = Forms! & strVar
or
dim frm as Form
strVar = "Forms!frmFormName"
set frm = strVar

in any way, for purposes of using the form name as a variable?

Thanks for your attention.
Feb 27 '07 #1
Share this Question
Share on Google+
4 Replies


100+
P: 176
Hi All.

Is it possible to concentrate
dim frm as Form
set frm = Forms! & strVar
or
dim frm as Form
strVar = "Forms!frmFormName"
set frm = strVar

in any way, for purposes of using the form name as a variable?

Thanks for your attention.
No need to help, I've found the answer:

strVar = "frmFormName"
set frm = me(strVar)
Feb 27 '07 #2

NeoPa
Expert Mod 15k+
P: 31,494
Michael, I'm afraid what you have isn't quite right :(
If you want a variable that references the current form (The form associated with the module rather than the currently selected form I mean) then Me on its own is required.
Me is already available obviously, but can also be used as :
Expand|Select|Wrap|Line Numbers
  1. Set frm = Me
Normally in this case it is sufficient to use Me.
If you have a form's name already in a string (say strVar) you would instead use :
Expand|Select|Wrap|Line Numbers
  1. Set frm = Forms(strVar)
Feb 28 '07 #3

100+
P: 176
Expand|Select|Wrap|Line Numbers
  1. Set frm = Me
Normally in this case it is sufficient to use Me.
If you have a form's name already in a string (say strVar) you would instead use :
Expand|Select|Wrap|Line Numbers
  1. Set frm = Forms(strVar)
Thanks, NeoPa.

That actually works.

What do I have to do in case of subform, I've tried the following with no success:
Expand|Select|Wrap|Line Numbers
  1.     Dim frm As Form
  2.     Dim strForm, strForm1, strForm2 As String
  3.     strForm = "Customers"
  4.     srtForm1 = "Customer_Details"
  5.     strForm2 = "Form"
  6.     Set frm = Forms(strForm)(strForm1)(strForm2) 'doesn't work
  7.     Set frm = Forms(strForm)(strForm1) 'doesn't work
  8.     Debug.Print frm.Filter
Mar 1 '07 #4

NeoPa
Expert Mod 15k+
P: 31,494
Thanks, NeoPa.
That actually works.
Oh, sound surprised why don't you :D
What do I have to do in case of subform, I've tried the following with no success:
Expand|Select|Wrap|Line Numbers
  1.     Dim frm As Form
  2.     Dim strForm, strForm1, strForm2 As String
  3.     strForm = "Customers"
  4.     srtForm1 = "Customer_Details"
  5.     strForm2 = "Form"
  6.     Set frm = Forms(strForm)(strForm1)(strForm2) 'doesn't work
  7.     Set frm = Forms(strForm)(strForm1) 'doesn't work
  8.     Debug.Print frm.Filter
Not a problem Michael.
Here's one I prepared earlier...
(Referring to Items on a Sub-Form).
Let me know if you have any problems after reading that.
Mar 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.