Hi everyone, I'm new to these forums, but I'm having a bit of an issue. I'm basically trying to get the coding right on the wherecondition, but can't seem to figure out the correct formatting for using multiple entries. This is being used to make a report that pulls selected addresses by name. List2 is a List box, and the For loop creates data that looks like this: "Bill" OR "Jim" OR "Sandy"
Anyway, here's the code. - Private Sub Command11_Click()
-
On Error GoTo Err_Command11_Click
-
-
Dim x As Integer
-
Dim y As String
-
Dim z As String
-
Dim stDocName As String
-
-
z = ""
-
For x = 0 To List2.ListCount - 1
-
y = List2.Column(0, x)
-
y = """" & y & """"
-
If x = 0 Then
-
z = y
-
Else
-
z = z & " OR " & y
-
End If
-
Next x
-
stDocName = "rptAddresses"
-
DoCmd.OpenReport stDocName, acPreview, , "ccustno='" & z & "'"
-
-
Exit_Command11_Click:
-
Exit Sub
-
-
Err_Command11_Click:
-
MsgBox Err.Description
-
Resume Exit_Command11_Click
-
-
End Sub
9 1755
Hi everyone, I'm new to these forums, but I'm having a bit of an issue. I'm basically trying to get the coding right on the wherecondition, but can't seem to figure out the correct formatting for using multiple entries. This is being used to make a report that pulls selected addresses by name. List2 is a List box, and the For loop creates data that looks like this: "Bill" OR "Jim" OR "Sandy"
Anyway, here's the code. - Private Sub Command11_Click()
-
On Error GoTo Err_Command11_Click
-
-
Dim x As Integer
-
Dim y As String
-
Dim z As String
-
Dim stDocName As String
-
-
z = ""
-
For x = 0 To List2.ListCount - 1
-
y = List2.Column(0, x)
-
y = """" & y & """"
-
If x = 0 Then
-
z = y
-
Else
-
z = z & " OR " & y
-
End If
-
Next x
-
stDocName = "rptAddresses"
-
DoCmd.OpenReport stDocName, acPreview, , "ccustno='" & z & "'"
-
-
Exit_Command11_Click:
-
Exit Sub
-
-
Err_Command11_Click:
-
MsgBox Err.Description
-
Resume Exit_Command11_Click
-
-
End Sub
Here is 1 Not-So-Obvious solution run against my Test Data. It has been debugged and is fully functional. Copy and Paste the code, make your necessary substitutions, and you should be ready to go. Let me know how you make out. - Dim x As Integer
-
Dim y As String
-
Dim z As String
-
Dim stDocName As String
-
-
stDocName = "rptEmployees"
-
-
z = ""
-
For x = 0 To List2.ListCount - 1
-
y = "[LastName]='" & List2.Column(0, x) & "'"
-
If x = 0 Then
-
z = y
-
Else
-
z = z & " Or " & y
-
End If
-
Next x
-
-
DoCmd.OpenReport stDocName, acViewPreview, , z
You can't do: -
SomeField = "Value1" OR "Value2"
-
You have two options: -
SomeField = "Value1" OR SomeField = "Value2"
-
SomeField In ("Value1", "Value2")
-
You can't do: -
SomeField = "Value1" OR "Value2"
-
You have two options: -
SomeField = "Value1" OR SomeField = "Value2"
-
SomeField In ("Value1", "Value2")
-
Hello Rabbit:
I don't think the IN approach will work within the current context. It interprets the individual items within the IN construct as additional, and illegal, Arguments to the OpenReport() Method. This was my initial approach to the problem but didn't seem to be workable because of the stated reason. Just some useless information I figured you may possibly want to know. See ya later!
Hi -
-
z = ""
-
For x = 0 To List2.ListCount - 1
-
y = List2.Column(0, x)
-
y = """" & y & """"
-
If x = 0 Then
-
z = y
-
Else
-
z = z & " OR " & y
-
End If
-
Next x
-
stDocName = "rptAddresses"
-
DoCmd.OpenReport stDocName, acPreview, , "ccustno='" & z & "'"
Hi
I think this may be a little simpler. -
z = "ccustno = '" & List2.Column(0, 0) & "'"
-
For x = 1 To List2.ListCount - 1
-
z = z & " OR ccustno = '" & List2.Column(0, x) & "'"
-
Next x
-
stDocName = "rptAddresses"
-
DoCmd.OpenReport stDocName, acPreview, , z
-
This assumes there is at least one item in the list, and if not you would need to test for the condition anyway.
MTB
Hello Rabbit:
I don't think the IN approach will work within the current context. It interprets the individual items within the IN construct as additional, and illegal, Arguments to the OpenReport() Method. This was my initial approach to the problem but didn't seem to be workable because of the stated reason. Just some useless information I figured you may possibly want to know. See ya later!
I just tried this and this works: -
Private Sub Command0_Click()
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stLinkCriteria = "UserID In (""Andy"", ""Bill"")"
-
stDocName = "Form1"
-
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
End Sub
-
I just tried this and this works: -
Private Sub Command0_Click()
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stLinkCriteria = "UserID In (""Andy"", ""Bill"")"
-
stDocName = "Form1"
-
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
-
End Sub
-
Thanks for the info, Rabbit. I really wasn't kidding when I said that I was giving you some useless information. (LOL).
Thank you everyone for all your responses, I was able to get it working with Mike's simplified version. I've bookmarked this site and plan to return if I run into any more snags, thanks!
Thank you everyone for all your responses, I was able to get it working with Mike's simplified version. I've bookmarked this site and plan to return if I run into any more snags, thanks!
Technically mines is simpler but no hard feelings. lol.
Anyways, glad you got it working.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joe |
last post by:
Hey,
I'm going to give some background on my situation in case anyone can
point out a way around my problem altogether... for the problem
itself, please skip to the bottom of the post. thanks....
|
by: Job Lot |
last post by:
I have tow columns in my DataTable Date, Amount. What would be the best way to create multiple entries in my DataTable? I am given a start date, end date and an amount. I want to create multiple...
|
by: ccr |
last post by:
Please view in a text editor so that the columnar text lines up. I
used Terminal 9pt font to compose this post and copied/pasted to my
newsreader program.
I am writing in the hope that one of...
|
by: ccr |
last post by:
Reposted with a longer line length. Apologies if I did not cancel the 1st attempt before you got
it.
If necessary, please view in a text editor so the columnar text lines up. I used Terminal...
|
by: Sammy |
last post by:
On a Windows 2003 Server machine that has multiple IIS web
sites, how does one control which web site the new web
application gets created under?
Thank you,
Sammy
|
by: Bernard Lebel |
last post by:
Hello,
Is there an option or a way to allow the selection of multiple entries
in the Listbox widget? I could not find any, and would like to allow
the end user to select multiple entries.
...
|
by: kevooo5 |
last post by:
I use Access 2003 and I'm having trouble setting the wherecondition for the Openform functions.
Usually it would look something like this
DoCmd.OpenForm "Contact", , ,wherecondition here
I...
|
by: TechnoAtif |
last post by:
<?php
include "dbconnect.php";
include "commonFunc.php"; ?>
<!---------------------------------->
<table width="80%" border="1" cellpadding="2" cellspacing="0">
<tr >
<td...
|
by: rik |
last post by:
I am trying to build an Access 2002/2003 database application that I
would like to offer to other writers so they can track submissions.
Just trying to make a helpful tool for writers, poets, or...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |