Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Problem with Userform and different code modules

Hi,

I have a problem with a Userform which I use for a double purpose. Because
everything is complex, I split up the procedures in different modules. Here
comes the problem: the pointer to the userform gets lost when I execute a
procedure in a different module than the first module that is chosen by the
form. Can I solve this, or must I put everything in the first called
module?

An example makes everything clear (this is a simplification, in fact, it
runs more than 1000 lines of code, that's why it is put in different code
modules!)

Thanks for your help!
Jos Vens

Public gnProgram as Integer

'Module of the userform

'Button1
Private Sub bButton1_Click()
LOGIN1_bButton_Click
End Sub

'Button2
Private Sub bButton2_Click()
LOGIN2_bButton_Click
End Sub

'Code Module LOGIN1

Function LOGIN1_bButton_Click() <<--- Here is FrmLogin is recognized because
it is called straight from the userform
gnProgram = 1
FrmLogin.oName.Visible = True
DCL_Login
End Function

'Code Module LOGIN2

Function LOGIN2_bButton_Click() <<--- Here is FrmLogin is recognized because
it is called straight from the userform
gnProgram = 2
FrmLogin.oName.Visible = False
DCL_Login
End Function

'Code Module DECLARATION <<--- Here is the problem: FrmLogin is no longer
recognized because it's another code module

Function DCL_Login()
FrmLogin.cbCombo1.Visible = (gnProgram = 1)
FrmLogin.cbCombo2.Visible = (gnProgram = 2)
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Problem with Userform and different code modules

Hi,

by writing the problem, I discovered myself the solution by passing the form
as a parameter to the other code module. It works! I only wonder if it's
the only way?

Calling:

DCL_Login FrmLogin

Function DCL_Login(vFrmLogin As UserForm)
vFrmLogin.cbCombo1.Visible = (gnProgram = 1)
vFrmLogin.cbCombo2.Visible = (gnProgram = 2)
End Function

Thanks anyway
Jos

"Jos Vens" schreef in bericht
...
Hi,

I have a problem with a Userform which I use for a double purpose.
Because everything is complex, I split up the procedures in different
modules. Here comes the problem: the pointer to the userform gets lost
when I execute a procedure in a different module than the first module
that is chosen by the form. Can I solve this, or must I put everything in
the first called module?

An example makes everything clear (this is a simplification, in fact, it
runs more than 1000 lines of code, that's why it is put in different code
modules!)

Thanks for your help!
Jos Vens

Public gnProgram as Integer

'Module of the userform

'Button1
Private Sub bButton1_Click()
LOGIN1_bButton_Click
End Sub

'Button2
Private Sub bButton2_Click()
LOGIN2_bButton_Click
End Sub

'Code Module LOGIN1

Function LOGIN1_bButton_Click() <<--- Here is FrmLogin is recognized
because it is called straight from the userform
gnProgram = 1
FrmLogin.oName.Visible = True
DCL_Login
End Function

'Code Module LOGIN2

Function LOGIN2_bButton_Click() <<--- Here is FrmLogin is recognized
because it is called straight from the userform
gnProgram = 2
FrmLogin.oName.Visible = False
DCL_Login
End Function

'Code Module DECLARATION <<--- Here is the problem: FrmLogin is no longer
recognized because it's another code module

Function DCL_Login()
FrmLogin.cbCombo1.Visible = (gnProgram = 1)
FrmLogin.cbCombo2.Visible = (gnProgram = 2)
End Function




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running code behind a userform cdb Excel Programming 17 February 10th 05 03:53 PM
UserForm-Code Problem Jim May Excel Programming 3 December 30th 04 04:28 PM
When to code in sheet or userform modules and when to use modules Tony James Excel Programming 1 December 16th 04 10:02 PM
editing code in modules through VB mark Excel Programming 2 August 12th 04 05:20 PM
Using the same variable in separate userform modules DarrenW Excel Programming 2 July 11th 03 03:11 AM


All times are GMT +1. The time now is 02:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"