Passing object names as arguements in functions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to pass the name of a form field object to a function. The Set
statement doesn't recognize the arguement as a variant or control data type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work using an
arguement either. For example, cvJoinTwo = Me![index_persons] assigns the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in advance for
your help.)
 
Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function
 
You need to pass the function the listbox, like this...

TestFunction Me.SomeListBox

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


Don Starnes said:
Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as you
specified.

What is wrong here? Thanks in advance for your help again.

Don

Ken Snell said:
Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I am trying to pass the name of a form field object to a function. The
Set
statement doesn't recognize the arguement as a variant or control data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work using
an
arguement either. For example, cvJoinTwo = Me![index_persons] assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in advance
for
your help.)
 
Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as you
specified.

What is wrong here? Thanks in advance for your help again.

Don

Ken Snell said:
Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I am trying to pass the name of a form field object to a function. The Set
statement doesn't recognize the arguement as a variant or control data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work using an
arguement either. For example, cvJoinTwo = Me![index_persons] assigns the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in advance for
your help.)
 
Just checking an obvious thing, but is the persons form open when you call
the function?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as you
specified.

What is wrong here? Thanks in advance for your help again.

Don

Ken Snell said:
Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I am trying to pass the name of a form field object to a function. The
Set
statement doesn't recognize the arguement as a variant or control data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work using
an
arguement either. For example, cvJoinTwo = Me![index_persons] assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in advance
for
your help.)
 
I call the function this way:

testfunction (Forms!persons!AllGroups)

And get an Object required error.

Forms!persons!AllGroups is the listbox.

Paul Overway said:
You need to pass the function the listbox, like this...

TestFunction Me.SomeListBox

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


Don Starnes said:
Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as you
specified.

What is wrong here? Thanks in advance for your help again.

Don

Ken Snell said:
Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

I am trying to pass the name of a form field object to a function. The
Set
statement doesn't recognize the arguement as a variant or control data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work using
an
arguement either. For example, cvJoinTwo = Me![index_persons] assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in advance
for
your help.)
 
I call the function from a button (add_persons) on the [persons] form:

Private Sub add_persons_Click()
' On Error GoTo statement
testfunction (Forms!persons!AllGroups)
'other statements
End Sub

The form is of course open when I click the button.

Ken Snell said:
Just checking an obvious thing, but is the persons form open when you call
the function?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as you
specified.

What is wrong here? Thanks in advance for your help again.

Don

Ken Snell said:
Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

I am trying to pass the name of a form field object to a function. The
Set
statement doesn't recognize the arguement as a variant or control data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work using
an
arguement either. For example, cvJoinTwo = Me![index_persons] assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in advance
for
your help.)
 
Is the listbox on a subform?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I call the function from a button (add_persons) on the [persons] form:

Private Sub add_persons_Click()
' On Error GoTo statement
testfunction (Forms!persons!AllGroups)
'other statements
End Sub

The form is of course open when I click the button.

Ken Snell said:
Just checking an obvious thing, but is the persons form open when you
call
the function?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as
you
specified.

What is wrong here? Thanks in advance for your help again.

Don

:

Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

I am trying to pass the name of a form field object to a function.
The
Set
statement doesn't recognize the arguement as a variant or control
data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work
using
an
arguement either. For example, cvJoinTwo = Me![index_persons]
assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in
advance
for
your help.)
 
No; it is on a regular form.

Ken Snell said:
Is the listbox on a subform?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I call the function from a button (add_persons) on the [persons] form:

Private Sub add_persons_Click()
' On Error GoTo statement
testfunction (Forms!persons!AllGroups)
'other statements
End Sub

The form is of course open when I click the button.

Ken Snell said:
Just checking an obvious thing, but is the persons form open when you
call
the function?

--

Ken Snell
<MS ACCESS MVP>

Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as
you
specified.

What is wrong here? Thanks in advance for your help again.

Don

:

Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

I am trying to pass the name of a form field object to a function.
The
Set
statement doesn't recognize the arguement as a variant or control
data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work
using
an
arguement either. For example, cvJoinTwo = Me![index_persons]
assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in
advance
for
your help.)
 
As I indicated earlier...

TestFunction Me.AllGroups

If AllGroups is also the name of a field, you should rename the listbox
lstAllGroups

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


Don Starnes said:
No; it is on a regular form.

Ken Snell said:
Is the listbox on a subform?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I call the function from a button (add_persons) on the [persons] form:

Private Sub add_persons_Click()
' On Error GoTo statement
testfunction (Forms!persons!AllGroups)
'other statements
End Sub

The form is of course open when I click the button.

:

Just checking an obvious thing, but is the persons form open when you
call
the function?

--

Ken Snell
<MS ACCESS MVP>

Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type
as
you
specified.

What is wrong here? Thanks in advance for your help again.

Don

:

Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

message
I am trying to pass the name of a form field object to a function.
The
Set
statement doesn't recognize the arguement as a variant or control
data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work
using
an
arguement either. For example, cvJoinTwo = Me![index_persons]
assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in
advance
for
your help.)
 
Ken and Paul--

I've found my error, and it is very BASIC (excuse the pun); I called the
function improperly:

testfunction (Forms!persons!AllGroups)

As Paul pointed out, using no parentheses is one better option.

I'm grateful for your help.

Ken Snell said:
Is the listbox on a subform?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I call the function from a button (add_persons) on the [persons] form:

Private Sub add_persons_Click()
' On Error GoTo statement
testfunction (Forms!persons!AllGroups)
'other statements
End Sub

The form is of course open when I click the button.

Ken Snell said:
Just checking an obvious thing, but is the persons form open when you
call
the function?

--

Ken Snell
<MS ACCESS MVP>

Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type as
you
specified.

What is wrong here? Thanks in advance for your help again.

Don

:

Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

I am trying to pass the name of a form field object to a function.
The
Set
statement doesn't recognize the arguement as a variant or control
data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work
using
an
arguement either. For example, cvJoinTwo = Me![index_persons]
assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in
advance
for
your help.)
 
doh! I missed the forest because of the tree....


--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
Ken and Paul--

I've found my error, and it is very BASIC (excuse the pun); I called the
function improperly:

testfunction (Forms!persons!AllGroups)

As Paul pointed out, using no parentheses is one better option.

I'm grateful for your help.

Ken Snell said:
Is the listbox on a subform?

--

Ken Snell
<MS ACCESS MVP>

Don Starnes said:
I call the function from a button (add_persons) on the [persons] form:

Private Sub add_persons_Click()
' On Error GoTo statement
testfunction (Forms!persons!AllGroups)
'other statements
End Sub

The form is of course open when I click the button.

:

Just checking an obvious thing, but is the persons form open when you
call
the function?

--

Ken Snell
<MS ACCESS MVP>

Ken--

Thanks for your reply. I tried using that code; this function call:

testfunction (Forms!persons!AllGroups)

gave this error:

Object required.

[AllGroups] is a list box on the form [persons].

The arguement for testfunction was declared as a control data type
as
you
specified.

What is wrong here? Thanks in advance for your help again.

Don

:

Try this:


Function testfunction(cvlistbox As Control)
' specify the list box
Set cvlist = cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
Set cvlist = Nothing
End Function


--

Ken Snell
<MS ACCESS MVP>

message
I am trying to pass the name of a form field object to a function.
The
Set
statement doesn't recognize the arguement as a variant or control
data
type.

For example:

Function testfunction(cvlistbox As Variant)
' specify the list box
Set cvlist = Me!cvlistbox
cvselected = cvlist.ItemsSelected.Count
If cvselected = 0 Then
MsgBox err_no_selection
End If
MsgBox "selection acknowledged"
End Function

Simply setting a variable to the value of an object doesn't work
using
an
arguement either. For example, cvJoinTwo = Me![index_persons]
assigns
the
value, but cvJoinTwo = Me!arguement does not.

How do I pass the name of an object to a function? (Thanks in
advance
for
your help.)
 
Back
Top