I have a listbox with a row source using a union query: - SELECT [quniReports].ReportID, [quniReports].ReportName, [quniReports].ReportCaption, [quniReports].ReportCriteriaFlags, [quniReports].ReportRemote FROM [quniReports] ORDER BY [quniReports].ReportCaption;
The union query sql: - TABLE [tblReports] UNION SELECT * FROM [tblReportsState];
-
tblReportsState is a linked table.
Question:
If the db is opened and the linked table is not linked: - Const conLINKED_SR As String = "tblReportsState"
-
-
If Len(CurrentDb.TableDefs(conLINKED_SR).Connect) = 0 Then
-
how can I then change the listbox row source to only show data in tblReports? I assume I would put the code in the listbox before update event.
Thanks for the look.
13 2856 ChipR 1,287
Recognized Expert Top Contributor
Try something like: - Dim strRowSource as String
-
-
strRowSource ="SELECT ReportID, ReportName, ReportCaption, ReportCriteriaFlags, ReportRemote FROM ([tblReports]"
-
-
If Len(CurrentDb.TableDefs(conLINKED_SR).Connect) > 0 Then
-
strRowSource = strRowSource & "UNION SELECT * FROM [tblReportsState]) "
-
else
-
strRowSource = strRowSource & ") "
-
end if
-
-
strRowSource = strRowSource & "ORDER BY ReportCaption"
Thanks Chip but it didn't work. I've tried removing my linked db, moving it's path manually and all I get is a blank listbox.
ChipR 1,287
Recognized Expert Top Contributor
Try a
MsgBox strRowSource
right before you set the listbox. Then you can take a look at it to make sure it looks valid in either case. That's the easiest way to reveal a mistake I may have made in concatenating the strings.
ChipR 1,287
Recognized Expert Top Contributor
Forgot to mention that the code would be in the form's open event probably.
Minor error in line 5 of post 2, Chip - the literal value referring to the name of a table in the tabledefs collection has to be within quotes: - If Len(CurrentDb.TableDefs("conLINKED_SR").Connect) > 0 Then
I would suggest placing the code in the on-load event of the form, not on open (as the underlying recordset for the form is not available until the form is loaded), then performing a requery of the control after setting its rowsource; the name of the control has not been mentioned, but the line needed is simply
Me![Name of listbox control].Requery
which should be placed after the lines setting the rowsource.
Ah, but what is also missing is the setting of the control's rowsource to the string.
Me![Name of listbox control].RowSource = strRowSource
This must be placed before the requery line in the final code...
Chip's code then becomes - Dim strRowSource as String
-
strRowSource ="SELECT ReportID, ReportName, ReportCaption, ReportCriteriaFlags, ReportRemote FROM [tblReports]"
-
If Len(CurrentDb.TableDefs("conLINKED_SR").Connect) > 0 Then
-
strRowSource = strRowSource & " UNION SELECT * FROM [tblReportsState] "
-
end if
-
strRowSource = strRowSource & " ORDER BY ReportCaption;"
-
With Me![Name of listbox control]
-
.RowSource = strRowSource
-
.Requery
-
End With
Finally, keep in mind that Union queries will only work if the number of fields and their types are exactly the same in both sets - so your table and the SELECT query must have the same number of fields, of the same type, in the same selection order if the union is to work at all.
-Stewart
here's the generated sql string: - SELECT ReportID, ReportName, ReportCaption, ReportCriteriaFlags, ReportRemote FROM ([tblReports]UNION SELECT * FROM [tblReportsState])
Which errors with a 'syntax error in join operation' at the word UNION.
Thanks Stewart, I have the code in the tab control like this: - If TabCtl2.Value = 7 Then
-
-
On Error GoTo Err_lstReportName_Click
-
-
Const conLINKED_SR As String = "tblReportsState" ' linked State Reports table
-
Dim strRowSource As String
-
-
strRowSource = "SELECT ReportID, ReportName, ReportCaption, ReportCriteriaFlags, ReportRemote FROM ([tblReports]"
-
-
If Len(CurrentDb.TableDefs(conLINKED_SR).Connect) > 0 Then
-
-
'OK, we know that conLINKED_SR is a Linked Table, but is the Link valid?
-
'The next line of code will generate Errors 3011 or 3024 if it isn't
-
CurrentDb.TableDefs(conLINKED_SR).RefreshLink
-
-
strRowSource = strRowSource & "UNION SELECT * FROM [tblReportsState]) "
-
-
Me.lstReportName.RowSource = strRowSource
-
Me.lstReportName.Requery
-
-
MsgBox strRowSource
-
-
Else
-
-
strRowSource = strRowSource & ") "
-
strRowSource = strRowSource & "ORDER BY ReportCaption"
-
-
End If
-
-
ChipR 1,287
Recognized Expert Top Contributor
Yep. In post #2, line 3 should have ended with:
FROM ([tblReports] "
I forgot the space at the end, so the resulting string got mashed.
Post #8 is my current code placed in the tab control. I added the space at the end so now it reads: - strRowSource = "SELECT ReportID, ReportName, ReportCaption, ReportCriteriaFlags, ReportRemote FROM ([tblReports] "
Still no go.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bill Brinkworth |
last post by:
I want the user to type in part of a word, and I want to return all words
from an Access word table that contains specified letters. If they were to
type "fe??", it should return all words in the dictionary that are 4 letters
and begin with "fe" into a listbox. I am having difficulting searching for
all words and taking all those words and populating a listbox. Can you help?
Here's what I have:
CLASS -
Public Property word() As String...
|
by: Paradigm |
last post by:
I am using Access 2K as a front end to a MYSQL database.
I am trying to run a Union query on the MYSQL database. The query is (much
simplified)
SELECT as ID from faxdata UNION
SELECT as ID from letdata UNION
SELECT as ID FROM MEMODATA;
I get an ODBC error. The same query runs when the backend files are MDB
files and it runs with MYSQL if I only combine 2 tables.
|
by: collie |
last post by:
Hi,
I have 2 listboxes. The first gets populated from the db as soon as
the page loads. The second listbox get populated based on the user's
selection from the first listbox. However, currently the code is
such that with each selection there is a postback. We want to avoid it
using filter and javascript. I am not using ADO.NET but adodbc and no
datagrids or datasets (please don't tell me that i should as my boss
clearly doesn't want...
|
by: Chris Leuty |
last post by:
I am populating a multiselect Listbox from a dataset, with the content of
the listbox filled by one table, and the selections determined from another
table. So far, I have been keeping the dataset a denormalized mirror of the
database, but I'm not having much luck getting the selection logic down (I
haven't found a 'hook' where I can access the listbox object as an object to
set the listitem's selected property before it gets rendered)..
...
|
by: P K |
last post by:
I have a listbox which I am populating on the client (it contains a list of
dates selected from calender). The listbox is a server control.
When I get to the server after postback by selecting an item in the list,
the list box cannot be accessed.
How do I repopulate the listbox on the server after postback and be able to
access the elements?
| |
by: mikes |
last post by:
I have 2 separate queries, which effectively are the same except they
draw data from separate tables. Both tables are (design-wise)
identical, only the data is different. for each query, there are 2
tables with a standard LEFT JOIN. One field of the query is calculated,
looking for a NULL in one table, and then using a field from the second
table in that case. One query looks like this:
PARAMETERS Text ( 255 );
SELECT...
|
by: halberd4 |
last post by:
Hello. I have an Access2003 db that I need to create a 'combined' query for. This query will then become the source for a listbox. The query needs to combine Query1 (example)
SELECT Aa, Bb, Cc, Dd FROM Table1
WHERE Cc=3
ORDER BY Aa, Bb, Dd
with Query2 (example)
SELECT Aa, Bb, Cc, Dd FROM Table1
WHERE Cc<>3
ORDER BY Cc, Aa, Bb, Dd
and produce a combined output similar to this (minus header)
Aa Bb Cc Dd
|
by: wugon.net |
last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad
query performance
Env:
db2 LUW V8 + FP14
Problem :
We have history data from 2005/01/01 ~ 2007/05/xx in single big
table,
we try separate this big table into twelve tables and create a view
|
by: mcalex |
last post by:
Hi, I'm having trouble trying to populate a list box with data from a parameterized query.
If I set the rowsource property to the query name, when the form opens I get the parameter values dialog, but I want to pass the params from code.
If I create a querydef, I can pass the parameter in, but I don't know how to get the records into the listbox. I have tried
lstNames = qdfNames.sql
lstNames.recordset = qdfNames.OpenRecordset;
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |