Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First shot at using a Global Module Sub 3

Status
Not open for further replies.

delman333

Technical User
Oct 20, 2003
32
US
Now that I've gotten most of the forms started...I've noticed a lot of routines that are common across them. Hmmm...global? Well here is the first code and naturally it doesn't work. I've created a Module called Routines and put the following Public Sub in it.

Public Sub ClearItem(SelectedForm As String, ByVal Pctl As Control, ByVal Nctl As Control, ByVal Tctl As Control, ByVal Qctl As Control)

SelectedForm Pctl.Enabled = False
SelectedForm Nctl.Enabled = False
SelectedForm Tctl.Enabled = False
SelectedForm Qctl.Enabled = False
SelectedForm Pctl.Value = Null
SelectedForm Nctl.Value = Null
SelectedForm Tctl.Value = Null
SelectedForm Qctl.Value = Null

End Sub

I have an editing form from which I call this Sub using the following code:

Call Routines.ClearItem("Forms!ScenarioOrdnanceForm!", P01, N01, T01, Q01)

It is then suppose to act on the SelectedForm but I get the Runtime 424 error: Object required.


Any suggestions would be great.
 
Hi,

1st - only pass the form name:

Call Routines.ClearItem("ScenarioOrdnanceForm", P01, N01, T01, Q01)

2nd - pass it as a 'form':

Public Sub ClearItem(SelectedForm As Form,...

3rd - refer to it as you would normally:

SelectedForm!Pctl.Enabled = False
(notice the ! after the 'form' variable?)


Hope this helps,

Darrylle



"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Ok...thanks...I got the Forms part working right. Here is the new code:

Public Sub ClearItem(SelectedForm As Form, Pctl As Control, Nctl As Control, Tctl As Control, Qctl As Control)

SelectedForm!Pctl.Enabled = False
SelectedForm!Nctl.Enabled = False
SelectedForm!Tctl.Enabled = False
SelectedForm!Qctl.Enabled = False
SelectedForm!Pctl.Value = Null
SelectedForm!Nctl.Value = Null
SelectedForm!Tctl.Value = Null
SelectedForm!Qctl.Value = Null

Call Routines.ClearItem(Forms.ScenarioOrdnanceForm, P01, N01, T01, Q01)

However, I now get the 2465 Error saying it can't find the field "Pctl".

But if I change it to the actual field name like this:

SelectedForm!P01.Enabled = False
SelectedForm!N01.Enabled = False
SelectedForm!T01.Enabled = False
SelectedForm!Q01.Enabled = False
SelectedForm!P01.Value = Null
SelectedForm!N01.Value = Null
SelectedForm!T01.Value = Null
SelectedForm!Q01.Value = Null

Then it works fine.

Any more suggestions?
 
Hi,

I think that because you are passing the actual controls now instead of passing them ByVal, you can refer to them by the variable names directly, instead of through the form object. Ie:
Code:
Pctl.Enabled = False
Nctl.Enabled = False
Tctl.Enabled = False
Qctl.Enabled = False
Pctl.Value = Null
Nctl.Value = Null
Tctl.Value = Null
Qctl.Value = Null
This should work instead of having to refer to the SelectedForm object.

Also referring to the controls with the ! notation will not work, as it will be looking for a fieldname and is getting a control instead. To make that code work I think you need to use:
Code:
SelectedForm.Controls(Pctl.Name).Enabled

But anyway this doesn't matter as the code should work fine without using the form object at all, as in the first suggestion.

HTH

Dean :)
 
Hi!

Just building a little on DeanWilliams suggestion. Think the following notation would also work if you pass the controlnames as strings

[tt]Public Sub ClearItem(SelectedForm As Form, Pctl As String, ...

SelectedForm(Pctl).Enabled = False
...
SelectedForm(Pctl).Value = Null
...

Call Routines.ClearItem(Forms!ScenarioOrdnanceForm, "P01", "N01", "T01", "Q01")[/tt]

But this isn't very dynamic, it would be limited to only the arguments (controls) passed, wouldn't looping thru the form controls be better?

Here a little sample providing the same, also showing how to avoid doing something with a control with a given name.

[tt]dim ctl as control
for each ctl in SelectedForm.Controls
select case ctl.controltype
case actextbox
if ctl.name<>&quot;SomeControlName&quot;
ctl.enabled=false
ctl.value=null
end if
case accombobox
...
end select
next ctl[/tt]

HTH Roy-Vidar
 
Ok...thanks. Again the combination of all responses has helped solve one issue. Stars to both of you.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top