Hello,
I'm pretty new to this, but I'm working on an MS Access DB and I'm trying to create a query that will accept a column name as a parameter. The table is set up to show an employees base schedule and there is a seperate column for each hour of work. If the column has a value of 1, they're scheduled to work... if the value is 0 they aren't. We would like one query that can be used to return who is working for the given hour, but the problem is that the column names are named like h1, h2, h3, etc. and I can't figure out how to accept the column name as a parameter.
Generally I can do something like [@parametername] but that doesn't seem to work for column names. I also tried tablename.[@hour] but no luck there either.
Thanks!
P.S. Not sure if it matters but it's MS Access 2000
4 6756
Hello,
I'm pretty new to this, but I'm working on an MS Access DB and I'm trying to create a query that will accept a column name as a parameter. The table is set up to show an employees base schedule and there is a seperate column for each hour of work. If the column has a value of 1, they're scheduled to work... if the value is 0 they aren't. We would like one query that can be used to return who is working for the given hour, but the problem is that the column names are named like h1, h2, h3, etc. and I can't figure out how to accept the column name as a parameter.
Generally I can do something like [@parametername] but that doesn't seem to work for column names. I also tried tablename.[@hour] but no luck there either.
Thanks!
P.S. Not sure if it matters but it's MS Access 2000
__1 Create a Query called qryBaseSchedule which contains all your Fields (Name, h1 to h24, etc.) with no criteria.
__2 Name your Table tblBaseSchedule or adjust code.
__3 Create an Unbound Combo Box on a Form called cboHour and simply place the Hours in its single column (h1, h2, h3, h4, h5, h6, h7...).
__4 In the AfterUpdate Event of the Combo Box, place the following code: - Private Sub cboHour_AfterUpdate()
-
CurrentDb.QueryDefs("qryBaseSchedule").SQL = "Select * FROM " _
-
& "tblBaseSchedule Where [" & Me![cboHour] & "] =" & 1
-
DoCmd.OpenQuery "qryBaseSchedule"
-
End Sub
__5 Now, whenever you select an Hour in the Combo Box, all Records that contain a 1 in that specific Hour Field will be returned.
__6 There may be an easier Method, but it doesn't exactly come to mind right now. Any questions, feel free to ask.
Thanks for the reply. I'm still having some trouble and perhaps it will help if I give more background information.
Basically we have an ASP.Net/C# application that connects to an Access DB. There are about 100 queries currently stored in the Access DB and there are no problems calling and using them. However, there is a table that was poorly structured and the only way I can create a query that will do what I want is to pass a column name as one of the parameters (h1, h2, etc.). Is there any way to do that in Access? I keep reading through the Access help guides and nothing has worked.
I know that I could make 24 seperate queries and call those seperately, but that seems tedius and inefficient. I'm also thinking that I could just imbed the SQL in the application but I guess that's a last resort. Again, I'm pretty new to this and my main goal is to not break anything that's already working.
Thanks!
Thanks for the reply. I'm still having some trouble and perhaps it will help if I give more background information.
Basically we have an ASP.Net/C# application that connects to an Access DB. There are about 100 queries currently stored in the Access DB and there are no problems calling and using them. However, there is a table that was poorly structured and the only way I can create a query that will do what I want is to pass a column name as one of the parameters (h1, h2, etc.). Is there any way to do that in Access? I keep reading through the Access help guides and nothing has worked.
I know that I could make 24 seperate queries and call those seperately, but that seems tedius and inefficient. I'm also thinking that I could just imbed the SQL in the application but I guess that's a last resort. Again, I'm pretty new to this and my main goal is to not break anything that's already working.
Thanks!
To the best of my knowledge, there is no way to pass a Column Name as a Parameter in the Query Grid but I could be wrong. The only Method I know is what I previously had Posted (a combination of an SQL Statement and VBA code). Does it necessarily have to be a Stored Query?
NeoPa 32,556
Expert Mod 16PB
If I can't come up with a better solution (which I certainly can't atm) then you can use a technique 'similar' to ADezii's, in that it uses the SQL of an already designed QueryDef but simply modifies it for specific use.
You don't say what you want the query for so I can simply show how to set up the SQL.
Your qryBaseSchedule query should be set up to assume we always want to use [H1]. - Dim strSQL As String
-
strSQL = CurrentDb.QueryDefs!qryBaseSchedule.SQL
-
strSQL = Replace(strSQL, "[H1]", "[H" & Me!cboHour & "]")
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sean C. |
last post by:
Helpful folks,
Most of my previous experience with DB2 was on s390 mainframe systems
and the optimizer on this platform always seemed very predictable and
consistent. Since moving to a WinNT/UDB...
|
by: CSDunn |
last post by:
Hello,
I have a situation with MS Access 2000 in which I need to display report
data in spreadsheet orientation (much like a datasheet view for a form). If
you think of the report in terms of what...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much...
|
by: bhbgroup |
last post by:
I have a query on one large table. I only add one condition, i.e. a
date (the SQL reads like 'where date > parameterdate'.
This query is rather quick if 'parameterdate' is either explicitly...
|
by: Thomas Zimmermann |
last post by:
I have a form with a subform in datasheet view. Now, I want to trigger a
procedure (P1) each time the user selects an entire column (by clicking in
the heading) in the subform. The procedure (P1) I...
|
by: archana |
last post by:
Hi all
I ma having problem in sqldataadapter.
In my sql database i have one table containing column name as 'Name and
address'. Here 'and' is reserved word which i am using in column name.
In...
|
by: Roger |
last post by:
I have a stored procedure running on DB2 V7 Z/os calling a COBOL
program to do some inserts. The stored procedure have 3 input columns
and one column is of varchar(32648)
The stored procedure is...
|
by: smaczylo |
last post by:
Hello, I've recently been asked to work with Microsoft Access, and
while I feel quite comfortable with Excel, I'm at a complete loss with
databases. If someone could help me with this issue I'm...
|
by: Mahendra Kumar Kutare |
last post by:
I am trying to implement a webserver with boss-worker model thread
pool implementation -
I have a header declaration threadpool.h as -
typedef struct threadpool_work {
void (*routine) ();...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |