A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Multi Select For Query



 
 
Thread Tools Display Modes
  #1  
Old May 5th, 2010, 05:29 AM posted to microsoft.public.access.forms
Ryan
external usenet poster
 
Posts: 551
Default Multi Select For Query

I have copied the following code into my Database however I cannot get it to
work if the field is of a Date type. I can change the varValue data type from
Variant to Date however this then damages all other fields. Any ideas?

Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function
  #2  
Old May 5th, 2010, 04:38 PM posted to microsoft.public.access.forms
Dorian
external usenet poster
 
Posts: 542
Default Multi Select For Query

"I cannot get it to work if the field is of a Date type."
What does this mean? What happens?
It sounds like you need to treat date data as a string, you can use CStr()
function?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"Ryan" wrote:

I have copied the following code into my Database however I cannot get it to
work if the field is of a Date type. I can change the varValue data type from
Variant to Date however this then damages all other fields. Any ideas?

Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function

  #3  
Old May 5th, 2010, 05:01 PM posted to microsoft.public.access.forms
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Multi Select For Query

Ryan -

What do you mean by 'damages all other fields'?

Have you stepped through the code to see what is happening?

I don't understand this piece of code - why would you convert a date (which
is stored as a number) to a string, and then try to compare it to a date in
the list box? I would remove this (comment it out).
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If

If there could be some dates and some date/times in the comparison, I would
change the comparison to be this:
If DateValue(lbo.ItemData(item)) = DateValue(varValue) Then

You also need your function statement to set varValue As Date.

If this doesn't help, let us know what you mean by 'damages other fields'...

--
Daryl S


"Ryan" wrote:

I have copied the following code into my Database however I cannot get it to
work if the field is of a Date type. I can change the varValue data type from
Variant to Date however this then damages all other fields. Any ideas?

Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:46 PM.


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