Session object

Dave_cha

Registered User.
Local time
Today, 16:32
Joined
Nov 11, 2002
Messages
119
I'm trying to define a session object based on a form name which could then be refered to from another form. So far I've been able to declare the form name as a string when FORM A opens using the following code...

LetActiveForm() = "[Forms]![Form A]"

Module used......
Option Compare Database
Option Explicit

Private ActiveForm As String

Public Property Get GetActiveForm() As String
GetActiveForm = ActiveForm
End Property

Public Property Let LetActiveForm(ByVal vNewValue As Variant)
ActiveForm = vNewValue
End Property


I've then tried to use the declared string as an object in FORM B....

Dim ActiveFormObj As Object
Set ActiveFormObj = GetActiveForm()
ActiveFormObj.Field1 = ..........



I'm getting Type Conversion Errors on the last step. It's fairly clear that I can't set an object equal to a string however I haven't managed to find a way around this.

Any help would be appreciated.

Rgd's,

Dave
 
You can refer to forms using strings as their name.

Dim strFormName As String
Dim ActiveFormObj As Form

strFormName = GetActiveForm() 'Have GetActiveForm return a String
Set ActiveFormObj = Forms(strFormName)
 
Thanks for the reply Modest.

I tried your suggestion as follows but am getting an error...

Dim strFormName As String
Dim ActiveFormObj As Form

LetActiveForm() = "[Forms]![FRM - EMP NEW ADD]"

strFormName = GetActiveForm() 'Retrieves Active Form as string
Set ActiveFormObj = Forms(strFormName)


Error...

...can't find the form 'Forms]![FRM - EMP NEW ADD' referred to in a macro expression or Visual Basic code.

Note the missing first and last brackets.

I've hardcoded the form name into the 'Set ActiveFormObj....' line and it works fine without any errors.

Any ideas?

Thanks,

Dave
 

Users who are viewing this thread

Back
Top Bottom