>> Properties

J

Jonathan

Hi, using Access version 2003. Most of my forms have manditory fields. So I
have a form variable (collection) that stores the names of the manditory
fields. When the form opens I load this collection. In the form_beforeUpdate
event I then call a public function located in a standard module. This
function then cycles through the form's collection to perform data validation
check.

Dim intLoop As Integer
Dim ctlName As String
For intLoop = 1 To myForm.mandatoryCtrlCount
ctlName = myForm.mandatoryCtrl(intLoop)

The first line calls a form property that returns a correct count of items
in the collection of field names. The next line returns a system error:

'Error 450 (Wrong number of arguments or invalid property assignment) in
procedure...'

The first line of the form property is:
Public Property Get manditoryCtrl(myItem As Integer) As String

If I call this same property from the form itself then the correct item is
returned. It is only when calling this property from the standard module that
an error is raised. Why?

I'm sure it's something blindingly obvious....

Any ideas or recommendations appreciated :)

Many thanks,
Jonathan
 
S

Stuart McCall

Public Property Get manditoryCtrl(myItem As Integer) As String

A GET property RETURNS a value. Here you're attempting to assign (LET) a
value (the parameter). Change this to:

Public Property Get manditoryCtrl() As String
 
J

Jonathan

Stuart McCall said:
A GET property RETURNS a value. Here you're attempting to assign (LET) a
value (the parameter). Change this to:

Public Property Get manditoryCtrl() As String
Hi Stuart,

Actually myItem is required by routine as an index for the item in the
collection to return. For example
myForm.mandatoryCtrl(1) returns the string "rsDate"

Thanks, Jonathan
 
S

Stuart McCall

Jonathan said:
Hi Stuart,

Actually myItem is required by routine as an index for the item in the
collection to return. For example
myForm.mandatoryCtrl(1) returns the string "rsDate"

Thanks, Jonathan

Duh. Because I made such an obvious boob, I re-read your post more
carefully. I see what you're doing now (or attempting to do). The only thing
I can think of is: do you happen to have a control on myForm called
mandatoryCtrl? If so (or even if not), presuming you set myForm like:

Set myForm = Forms!MyFormName

you could instead of the myForm variable try:

Form_MyFormName.mandatoryCtrl(intLoop)

(ie as your form is listed in the VBE project explorer window). That way
you're referring directly to the form's class module.

Been scratching my head for a while, but that's all I can come up with...
 
S

Stuart McCall

Jonathan said:
Hi Stuart,

Actually myItem is required by routine as an index for the item in the
collection to return. For example
myForm.mandatoryCtrl(1) returns the string "rsDate"

Thanks, Jonathan

Duh. Because I made such an obvious boob, I re-read your post more
carefully. I see what you're doing now (or attempting to do). The only thing
I can think of is: do you happen to have a control on myForm called
mandatoryCtrl? If so (or even if not), presuming you set myForm like:

Set myForm = Forms!MyFormName

you could instead of the myForm variable try:

Form_MyFormName.mandatoryCtrl(intLoop)

(ie as your form is listed in the VBE project explorer window). That way
you're referring directly to the form's class module.

Been scratching my head for a while, but that's all I can come up with...
 
J

Jonathan

Stuart McCall said:
Duh. Because I made such an obvious boob, I re-read your post more
carefully. I see what you're doing now (or attempting to do). The only thing
I can think of is: do you happen to have a control on myForm called
mandatoryCtrl? If so (or even if not), presuming you set myForm like:

Set myForm = Forms!MyFormName

you could instead of the myForm variable try:

Form_MyFormName.mandatoryCtrl(intLoop)

(ie as your form is listed in the VBE project explorer window). That way
you're referring directly to the form's class module.

Been scratching my head for a while, but that's all I can come up with...
Thanks Stuart,
I call this function using the following
Cancel = CheckMandatoryCtrlBeforeUpdate(Me)

So the myForm is set to the active form.

Just a reminder that the line
For intLoop = 1 To myForm.mandatoryCtrlCount
successfully calls the mandatoryCtrlCount property and returns the correct
collection items count. So a form reference and property reference has worked
once.

Many thanks,
Jonathan
 
S

Stuart McCall

Jonathan said:
Thanks Stuart,
I call this function using the following
Cancel = CheckMandatoryCtrlBeforeUpdate(Me)

So the myForm is set to the active form.

Just a reminder that the line
For intLoop = 1 To myForm.mandatoryCtrlCount
successfully calls the mandatoryCtrlCount property and returns the correct
collection items count. So a form reference and property reference has
worked
once.

Many thanks,
Jonathan

Well I'm baffled. I can't think of a single reason you should get this
behaviour.

Perhaps someone else has an idea? Maybe you should re-post and let this
thread die..

Sorry,
Stuart
 
S

Stuart McCall

Hi Jonathan

I had a little spare time this am, so I knocked up a quick test rig which
hopefully follows your model. It works just fine for me...

I created a form with a command button. The form's class module is:

Private col As Collection

Public Property Get ColCount() As Long
ColCount = col.Count
End Property

Public Property Get ColItem(idx As Integer) As String
ColItem = col(idx)
End Property

Private Sub Command0_Click()
test Me
End Sub

Private Sub Form_Load()
Set col = New Collection
col.Add "Stuart"
col.Add "McCall"
col.Add "Jonathan"
End Sub

'''''''''''''''''''''

and the module contains a public sub test:

Public Sub test(frm As Access.Form)
Dim i As Integer
For i = 1 To frm.ColCount
Debug.Print frm.ColItem(i)
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top