Pass variables from a subform?

NJudson

Who farted?
Local time
Today, 00:01
Joined
Feb 14, 2002
Messages
297
I'm using Access 2k and I've created a form ("frmAudits") with a subform ("subfrmImportSwitchData"). I've placed an optiongroup inside the subform that I'd like to pass the values to a module, but I keep getting the error, "Microsoft Access can't find the form 'SubForm' referred to in a macro or expression or Visual Basic Code."

In the General Declarations area in the module I've placed:
Public subfrmImportSwitchData As Form_subfrmImportSwitchData
Public optgrpsubfrmImportSwitchDataSelectSwitch As OptionGroup
Public optsubfrmImportSwitchDataFortWayne1 As OptionButton
Public optsubfrmImportSwitchDataFortWayne2 As OptionButton
Public optsubfrmImportSwitchDataAlexandria As OptionButton
Public optsubfrmImportSwitchDataLafayette As OptionButton
Public optsubfrmImportSwitchDataVidor As OptionButton

in my function to set the variables I have:

Set subfrmImportSwitchData = Forms!subfrmImportSwitchData
Set optgrpsubfrmImportSwitchDataSelectSwitch = subfrmImportSwitchData.optgrpsubfrmImportSwitchDataSelectSwitch
Set optsubfrmImportSwitchDataFortWayne1 = subfrmImportSwitchData.optsubfrmImportSwitchDataFortWayne1
Set optsubfrmImportSwitchDataFortWayne2 = subfrmImportSwitchData.optsubfrmImportSwitchDataFortWayne2
Set optsubfrmImportSwitchDataAlexandria = subfrmImportSwitchData.optsubfrmImportSwitchDataAlexandria
Set optsubfrmImportSwitchDataLafayette = subfrmImportSwitchData.optsubfrmImportSwitchDataLafayette
Set optsubfrmImportSwitchDataVidor = subfrmImportSwitchData.optsubfrmImportSwitchDataVidor

but it's crapping out on the line:
Set subfrmImportSwitchData = Forms!subfrmImportSwitchData

Is it not possible to pass values from a subform? I would have thought so but it doesn't seem to find or recognize the subform? Any ideas on something I'm overlooking? Thanks for any assistance.
 
this line

Public subfrmImportSwitchData As Form_subfrmImportSwitchData

is trying to dim the variable subfrmImportSwitchData as a custom object Form_subfrmImportSwitchData which I cannot see defined in your code.

Are you not simply wanting to define the variable as a form? ie

Public subfrmImportSwitchData As Form
 
You wrote
<<
Is it not possible to pass values from a subform? I would have thought so but it doesn't seem to find or recognize the subform? Any ideas on something I'm overlooking? Thanks for any assistance.
>>

It's not too clear from the code what you are trying to do.

If you have a subform,
and the subform contains an option group,
and you place event code ***in the subform***,
then you have no problem.

You refer to any control as Me![ControlName]

RichM
 
Sorry that I wasn't very clear in stating my problem. Let me try it again. I have a form with a subform on it with an option group control and a command button control. This command button on the subform runs the event code:

Private Sub cmdImportSwitchData_Click()
Call ImportFW1Switch
End Sub

The ImportFW1Switch function runs a series of other functions and subroutines. One of these functions in the series requires the value of the optiongroup from the subform. I want to be able to pass the value of the optiongroup control over to the module so the function can perform the code.

My problem lies somewhere in setting up the variable so it can be passed. I've actually tried a test on a "test form" called frmTest. I got the same run-time error 2450 'Microsoft access can't find the form frmTest referred to in a macro expression or visual basic code.' I'm not sure if something's not correct in my Reference Library or what but it seems to be giving me the same error throughout the database and not limited to just that form that I'm trying to work on. Thanks for any help.
 
Looking at it again, to pass values to a module, pass the values as arguments to that module ie


Call ImportFW1Switch (me.optionGroupName)

when defining the Sub in the module,

Public Sub ImportFW1Switch (Byval intOptionValue)

This will tell the module that it is looking for a value passed with the sub ie your option group value. if you want this variable to be available for other functions, remove the ByVal from the statement and the variable will be passed, not the value.

Does this help any?
 
Set subfrmImportSwitchData = Forms!frmAudits!subfrmImportSwitchData.Form ?
 
Thank you all very much for your help. Looks like the prize goes to Fizzio. I didn't know it was possible to do that but I got it working great. Thanks a lot everyone.
 

Users who are viewing this thread

Back
Top Bottom