Making Form Name as Variable?

bboy

New member
Local time
Yesterday, 18:11
Joined
Jul 12, 2007
Messages
2
Hi,

I'm stuck. Hope someone can help. My MS ACCESS skill isn't great so this might be a stupid question. :rolleyes:

Is it possible and if so, how to I code in a way that I can make FORM names as a variable?

For example:
This particular code makes the Filter box = ABC on form "frmFilterIssue".

How can I make the part where "frmFilterIssue" is referenced into a variable so I can just feed it with different form names? This saves a lot of time writing long form names and repetitive codes.

Forms!frmFilterIssue!Filter1 = "ABC"

I thought some fancy quotations " " and && would do it but thats more like for SQL.

Forms! X !Filter1 = "ABC" - X is my variable... somehow I need to connect it properly..

Many thanks!

Bob
 
You have to set the correct data type.

Code:
Dim frmVariable As Form

frmVariable = Forms!FormName

Docmd.Open frmVariable
 
Try
Dim frmVariable As String

Forms(frmVariable)!Filter1="ABC"
 
Try
Dim frmVariable As String

Forms(frmVariable)!Filter1="ABC"

Slight correction:

You need a PERIOD, not the Bang between (as it is a property or method).

You could create a sub in a standard module to do what you want:
Code:
Public Sub SetFilter(strForm as String, strFilterValue)

   Forms(strForm).Filter="[YourIDFieldHere]=" & strFilterValue
   Forms(strForm).FilterOn = True
End Sub
 

Users who are viewing this thread

Back
Top Bottom