object required error

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

Guest

I am getting the object required error on the indicated line in the code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
You've declared xsortkey as a Control, but you've never instantiated it so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying to
refer to a control on that form)

Set xsortkey = Me!NameOfControl
 
Hooray! That did the trick. Thank you so much.

Douglas J. Steele said:
You've declared xsortkey as a Control, but you've never instantiated it so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
I am getting the object required error on the indicated line in the code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
I was premature - that got rid of the error, but what I am trying to pass is
the name of the control, not the contents. Can I do this?

Douglas J. Steele said:
You've declared xsortkey as a Control, but you've never instantiated it so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
I am getting the object required error on the indicated line in the code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should qualify it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SandyR said:
I was premature - that got rid of the error, but what I am trying to pass
is
the name of the control, not the contents. Can I do this?

Douglas J. Steele said:
You've declared xsortkey as a Control, but you've never instantiated it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
I am getting the object required error on the indicated line in the code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
I am using the sortkey parameter to set the sort property in the form I am
opening. It can be one of two different fields, depending on the option
chosen. So LastName is the name of the field on which I want to sort. What
actually is getting passes is the content of the field.

Douglas J. Steele said:
Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should qualify it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SandyR said:
I was premature - that got rid of the error, but what I am trying to pass
is
the name of the control, not the contents. Can I do this?

Douglas J. Steele said:
You've declared xsortkey as a Control, but you've never instantiated it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in the code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SandyR said:
I am using the sortkey parameter to set the sort property in the form I am
opening. It can be one of two different fields, depending on the option
chosen. So LastName is the name of the field on which I want to sort.
What
actually is getting passes is the content of the field.

Douglas J. Steele said:
Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should qualify it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SandyR said:
I was premature - that got rid of the error, but what I am trying to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
If I use the statement you suggested with XSORTKEY defined as a control, I
get the message "type mismatch" on the "LastName" portion from the compiler.
If I change the definition back to string, I get the "object required" error
Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SandyR said:
I am using the sortkey parameter to set the sort property in the form I am
opening. It can be one of two different fields, depending on the option
chosen. So LastName is the name of the field on which I want to sort.
What
actually is getting passes is the content of the field.

Douglas J. Steele said:
Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should qualify it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I was premature - that got rid of the error, but what I am trying to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
What line of code raises the error?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
If I use the statement you suggested with XSORTKEY defined as a control, I
get the message "type mismatch" on the "LastName" portion from the
compiler.
If I change the definition back to string, I get the "object required"
error
Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


SandyR said:
I am using the sortkey parameter to set the sort property in the form I
am
opening. It can be one of two different fields, depending on the
option
chosen. So LastName is the name of the field on which I want to sort.
What
actually is getting passes is the content of the field.

:

Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should qualify
it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I was premature - that got rid of the error, but what I am trying to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never
instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're
trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in
the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the
same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
The line that you suggested:

xsortkey = "LastName"

Douglas J. Steele said:
What line of code raises the error?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
If I use the statement you suggested with XSORTKEY defined as a control, I
get the message "type mismatch" on the "LastName" portion from the
compiler.
If I change the definition back to string, I get the "object required"
error
Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I am using the sortkey parameter to set the sort property in the form I
am
opening. It can be one of two different fields, depending on the
option
chosen. So LastName is the name of the field on which I want to sort.
What
actually is getting passes is the content of the field.

:

Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should qualify
it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I was premature - that got rid of the error, but what I am trying to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never
instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're
trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in
the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the
same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
Please repost all of the code, since you've made some changes since posting
the original code. Also indicate what type of control you're instantiating
xsortkey to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
The line that you suggested:

xsortkey = "LastName"

Douglas J. Steele said:
What line of code raises the error?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
If I use the statement you suggested with XSORTKEY defined as a
control, I
get the message "type mismatch" on the "LastName" portion from the
compiler.
If I change the definition back to string, I get the "object required"
error
on the xsortkey portion of the statement.

:

Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I am using the sortkey parameter to set the sort property in the form
I
am
opening. It can be one of two different fields, depending on the
option
chosen. So LastName is the name of the field on which I want to
sort.
What
actually is getting passes is the content of the field.

:

Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should
qualify
it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I was premature - that got rid of the error, but what I am trying
to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never
instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're
trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in
the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the
same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ")
in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
I have gotten it to work - I had to remove the word Set, and use a string
rather than a control for the sort key fieldname. Thank you so much for
your help -- you changed the way that I was thinking about the problem, which
enabled me to solve it.

For anyone who has been following this thread, here is my working code:

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim XSORTKEY As String
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
XSORTKEY = "LastName"
recordkey = LastName.Value
Else
XSORTKEY = "[street/location]"
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(XSORTKEY, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub

Douglas J. Steele said:
Please repost all of the code, since you've made some changes since posting
the original code. Also indicate what type of control you're instantiating
xsortkey to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
The line that you suggested:

xsortkey = "LastName"

Douglas J. Steele said:
What line of code raises the error?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


If I use the statement you suggested with XSORTKEY defined as a
control, I
get the message "type mismatch" on the "LastName" portion from the
compiler.
If I change the definition back to string, I get the "object required"
error
on the xsortkey portion of the statement.

:

Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I am using the sortkey parameter to set the sort property in the form
I
am
opening. It can be one of two different fields, depending on the
option
chosen. So LastName is the name of the field on which I want to
sort.
What
actually is getting passes is the content of the field.

:

Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should
qualify
it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I was premature - that got rid of the error, but what I am trying
to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never
instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're
trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line in
the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the
same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ")
in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub
 
Glad you got it working.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
I have gotten it to work - I had to remove the word Set, and use a string
rather than a control for the sort key fieldname. Thank you so much for
your help -- you changed the way that I was thinking about the problem,
which
enabled me to solve it.

For anyone who has been following this thread, here is my working code:

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with the same street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim XSORTKEY As String
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
XSORTKEY = "LastName"
recordkey = LastName.Value
Else
XSORTKEY = "[street/location]"
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(XSORTKEY, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

End Sub

Douglas J. Steele said:
Please repost all of the code, since you've made some changes since
posting
the original code. Also indicate what type of control you're
instantiating
xsortkey to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SandyR said:
The line that you suggested:

xsortkey = "LastName"

:

What line of code raises the error?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


If I use the statement you suggested with XSORTKEY defined as a
control, I
get the message "type mismatch" on the "LastName" portion from the
compiler.
If I change the definition back to string, I get the "object
required"
error
on the xsortkey portion of the statement.

:

Sounds, then, like you want

xsortkey = "LastName"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I am using the sortkey parameter to set the sort property in the
form
I
am
opening. It can be one of two different fields, depending on the
option
chosen. So LastName is the name of the field on which I want to
sort.
What
actually is getting passes is the content of the field.

:

Can you explain a bit more?

What's LastName: a variable, a control or a field in the form's
recordsource? (If it's a control or a field, you really should
qualify
it
with a reference to the form)



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I was premature - that got rid of the error, but what I am
trying
to
pass
is
the name of the control, not the contents. Can I do this?

:

You've declared xsortkey as a Control, but you've never
instantiated
it
so
that it points to a specific control.

You need something like:

Set xsortkey = Forms!NameOfForm!NameOfControl

or (if this is in the code associated with a form, and you're
trying
to
refer to a control on that form)

Set xsortkey = Me!NameOfControl

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I am getting the object required error on the indicated line
in
the
code
shown below. Can anyone tell me what I am doing wrong?

'---------------------------------------------------------------------------------------
' Procedure : find_related_Click
' DateTime : 12/28/2006 13:39
' Author : rosensan
' Purpose : open a window showing the list of items with
the
same
street
or last name
'---------------------------------------------------------------------------------------
'
Private Sub find_related_Click()

Dim xsortkey As Control
Dim recordkey As String


On Error GoTo find_related_Click_Error

If find_related = 1 Then
xsortkey = LastName <=======
recordkey = LastName.Value
Else
xsortkey = [street/location]
recordkey = [street/location].Value
End If

Call Form_Switchboard.OpenRelated(xsortkey, recordkey)

find_related_Click_exit:
On Error GoTo 0
Exit Sub

find_related_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description &
")
in
procedure
find_related_Click of VBA Document Form_Form1"
Resume find_related_Click_exit

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

Back
Top