Form Module Visible Yes/No Question (1 Viewer)

miken5678

Registered User.
Local time
Today, 03:43
Joined
Jul 28, 2008
Messages
113
I am trying to learn modules and while some of them tend to work others dont. I assumed you could per say nest different functions within a module without issue but advice and input is suggested as to any help to be provided.

Code:
Option Compare Database
Private Sub Form_Current()
Call WindStreetDirectoryFunction
End Sub
Private Sub Frame189_BeforeUpdate(Cancel As Integer)
If Frame189 = 1 Then
    txtQ17ic.Visible = True
    Label197.Visible = True
Else
    txtQ17ic.Visible = False
    Label197.Visible = False
End If
End Sub
Private Sub IndividualorEntity_BeforeUpdate(Cancel As Integer)
Call IndividualorEntityFunction
End Sub
Private Sub IndividualorEntity_AfterUpdate()
Call IndividualorEntityFunction
End Sub
Private Sub WindStreetDirectory_Frame_AfterUpdate()
Call WindStreetDirectoryFunction
End Sub
Private Sub WindStreetDirectory_Frame_BeforeUpdate(Cancel As Integer)
Call WindStreetDirectoryFunction
End Sub


Functions
Code:
Function WindStreetDirectoryFunction()
If WindStreetDirectory_Frame = 1 Then
    TabCtlIndividualorEntity.Visible = False
    Frame24 = 0
    Frame263 = 0
    Frame116 = 0
    Frame125 = 0
    Frame133 = 0
    Frame141 = 0
    Frame149 = 0
    Frame157 = 0
    Frame165 = 0
    Frame173 = 0
    Frame181 = 0
    Frame189 = 0
    txtQ17ic = 0
    Frame211 = 0
    Frame219 = 0
    Frame227 = 0
    Frame235 = 0
    Text243 = 0
    Frame245 = 0
    Frame253 = 0
    Text261 = 0
ElseIf WindStreetDirectory_Frame = 2 Then
    TabCtlIndividualorEntity.Visible = True
Else
End If
End Function
Function IndividualorEntityFunction()
If IndividualorEntity = 1 Then
    Name_Insured___Individual.Visible = True
    Named_Insured___Entity.Visible = False
ElseIf IndividualorEntity = 2 Then
    Name_Insured___Individual.Visible = False
    Named_Insured___Entity.Visible = True
Else
End If
End Function

Goal is to get the form to act based on input to show the user different tabs while at the same time when scrolling through past records the view will change back to the original. Currently with this setup the view does not change. However, if i manually do the vba into each before/after even of the item it tends to work fine. Can someone assist in telling me if I am going in the wrong direction?

thanks

mike
 

miken5678

Registered User.
Local time
Today, 03:43
Joined
Jul 28, 2008
Messages
113
I thought I might have had issues do to multiple functions in one module so I split them out. I have attached a zip file of the db.. the vba works fine when done manually on the form and in the before/after events however once in a module and referenced on the form there is no worky?

Since I am new to modules what am I doing wrong? Is it not possible to set me.visible items in this way?
 

Attachments

  • Wind & Contents Opt Out.zip
    322.5 KB · Views: 84

DCrake

Remembered
Local time
Today, 11:43
Joined
Jun 8, 2005
Messages
8,626
The thing that you are doing wrong is to place your form dependant functions in a standalone module without referencing the active form.

If the functions are only applicable to the form then copy them into the form module and delete the standard module.

The standalone module does not know what form you are talking about.
 

miken5678

Registered User.
Local time
Today, 03:43
Joined
Jul 28, 2008
Messages
113
I think I caught your drift. Let me know if right or wrong. I chose this method as only one form will be utlized however there will be a lot of silly validations as to choices made by the input in terms of what is visible and what is not visible/available.

I changed the modules to a similiar format like the following

Code:
Public Function WindStreetDirectoryFunction()
If Forms!WindOptOut!WindStreetDirectory_Frame = 1 Then
    Forms!WindOptOut!TabCtlIndividualorEntity.Visible = False
    Forms!WindOptOut!Frame24 = 0
    Forms!WindOptOut!Frame263 = 0
    Forms!WindOptOut!Frame116 = 0
    Forms!WindOptOut!Frame125 = 0
    Forms!WindOptOut!Frame133 = 0
    Forms!WindOptOut!Frame141 = 0
    Forms!WindOptOut!Frame149 = 0
    Forms!WindOptOut!Frame157 = 0
    Forms!WindOptOut!Frame165 = 0
    Forms!WindOptOut!Frame173 = 0
    Forms!WindOptOut!Frame181 = 0
    Forms!WindOptOut!Frame189 = 0
    Forms!WindOptOut!txtQ17ic = 0
    Forms!WindOptOut!Frame211 = 0
    Forms!WindOptOut!Frame219 = 0
    Forms!WindOptOut!Frame227 = 0
    Forms!WindOptOut!Frame235 = 0
    Forms!WindOptOut!Text243 = 0
    Forms!WindOptOut!Frame245 = 0
    Forms!WindOptOut!Frame253 = 0
    Forms!WindOptOut!Text261 = 0
ElseIf Forms!WindOptOut!WindStreetDirectory_Frame = 2 Then
    Forms!WindOptOut!TabCtlIndividualorEntity.Visible = True
Else
End If
End Function

and it appears it now starts to work.. i assume you have to always reference the form once it is inside a module and outside the form? Is there any issue with me doing this with modules that would lead to severe problems?
 

vicissitude

Registered User.
Local time
Today, 10:43
Joined
Feb 28, 2010
Messages
92

miken5678

Registered User.
Local time
Today, 03:43
Joined
Jul 28, 2008
Messages
113
slowly getting it. Makes me wonder if there is a reference to be used that is a variable where

Forms!WindOptOut!Text261
could be referenced as Forms!ActiveForm!Text261

thank you for all of your help and input thus far..
 

Users who are viewing this thread

Top Bottom