I have a query with fields defined from a table. I have a label on a form that I would like to add to this query, the forms name is params and the label name is match4. The labels caption can be changed on the form and I want that new caption to be in the query, can this be done. Any help would be appreciated.
Thanks again for your help.
11 5571 zmbd 5,501
Recognized Expert Moderator Expert
If you are talking about a query that you have built from the ribbon/menu then the only way is to use the qrydef collection.
Delete the old query and then rebuild and add it to the collection.
If you are talking about an sql string that is built in VBA and then used to open a record set, then just use the field caption in your code to build the string.
-z
Thanks for the reply. I'm not sure how to add a label from a form to a query. I use the simple query design not the wizard when I usually design a query, although I do also use the sql string to build query's when things in the query need to change. I not sure how to code a form label in the sql string or when I just use the query design.
zmbd 5,501
Recognized Expert Moderator Expert
OK
In order not to go into the deep end we're going to have to understand what it is you're doing. Although it is not unusual to change a label caption (I use them for user feed back) it is unusual to use the control as I suspect you are doing; thus, please provide some detail as to what you're doing with the form and some example code with an explanation of any errors. (when you post code, select it with the mouse and click the <code/> button above next to the undo/redo.
-z
Boy, let's see if I can explain this further. I really don't have any code to show you as the only thing the query does is export the data to a .txt file. But here's what I'm trying to accomplish. The Params form is used to set all the options for the program. In the params form the user can setup 5 events, this is where the label caption comes in, they can change the names of the events, this give the user a little more flexibility so instead of just a standard name they can name the event what ever they wish. The user then can export the data to the .txt file where a hand held computer will import that data. The data for the hand held computer comes from the single table but I want to have the event name also show up with that data. I probably could add some columns to the table and store the data in there but I would like to just and the caption fields to the query.
I hope this makes sense if not let me know and I'll try again.
Rabbit 12,516
Recognized Expert Moderator MVP
I don't understand either why you would want to include the label caption as a field in a query. Label captions don't change and are static unless you're using code/macros to change the caption value.
But if you use this in a query def, it will pull the label caption into the query. - SELECT PK, [Forms]![FormName]![LabelName].[Caption] AS LabelCaption
-
FROM someTable
With that, if my label caption is Name: and I have 3 records in the table, my results would be: zmbd 5,501
Recognized Expert Moderator Expert
I think what we have here is a failure to communicate
:) (chuckle)
Take a look at the following picture.
I believe that you are referring to textbox controls and not labels as labels are not normally something a user can modify in form view. So all of the "unbound" entries are controls for user interaction.
If we're talking about textbox controls then you have basically the same thing as Rabbit's just for values: - SELECT PK,
-
[Forms]![FormName]![TextBoxName].[Value]
-
AS TextBoxValue
-
FROM someTable
-z
I understand the difference between the Textbox and the Label and I do use the Label. I know this is probably not the correct way to do this but because this is a new option in the program to extract this data out to a .txt file I'm trying to make it so I don't have to make big changes to the program. I tried the do the querydef but it doesn't work here's the code to build the query - (A cut and paste may not work on this )
-
Set ExtractParm = db.QueryDefs("Extractparm")
-
ExtractParm.SQL =
-
"SELECT [forms]![Params]![Match4].[Caption]
-
as EventName,
-
Params.Club_name, Params.RegionalName,
-
Params.WildbunchStages, Params.Wildbunchdate,
-
Params.RankPointsWB, Params.TotalTimeWB,
-
Params.RankbyClassWB, Params.WBShotPoint,
-
Params.MisseTime, Params.PenaltiesTime,
-
Params.BonusstageWB1, Params.BonusstageWB2," & _
-
"Params.BonusstageWB3, Params.BonusstageWB4,
-
Params.BonusstageWB5, Params.BonusstageWB6,
-
Params.BonusstageWB7, Params.BonusstageWB8,
-
Params.BonusstageWB9, Params.BonusstageWB10,
-
Params.BonusstageWB11, Params.BonusstageWB12," & _
-
"Params.MatchDQTotal, Params.StageDQTotal,
-
Params.DNFTotal, Params.StageDQTargets,
-
Params.TargetPlus
-
FROM Params"
When I run the query it ask for a value to enter in the forms field.
zmbd 5,501
Recognized Expert Moderator Expert
CD Tom,
Hopefully you got the tag line... it's a play on Cool Hand Luke and the chuckle
I really was hoping that you ment text boxes and not labels. This would have been a very straight forward way of building a query.
By using labels for a job that text boxes are designed to do, you make your coding that much more difficult and the enduser will truely dislike haveing a dozen prompts showup (and I'm guessing here...) You won't beable to intercept the responses to build the query as you want because the engine is trying to get the values to compare against data... not values to build fields.
By using the textboxes, your user opens the form, enters the text in the boxes, and the vba builds the query for them when what ever command button is pressed. You can take the values and use them in a "where" clause or use them to build the query structure.
The effort (IMHO) to try and do what I think you are attempting will be somewhat the same, actually I think more difficult, as redoing what you've already done.
-z
I guess I'll try and change those labels to textboxs and give that a try. Thanks for you advice and help.
Ok, I changed those labels to textboxs and change the querydefs to .[value] but I get the same thing. I think maybe I need to come up with some other way to get this done.
Thanks for all your help.
zmbd 5,501
Recognized Expert Moderator Expert
CD Tom,
Don't give up just yet.
Let's look at the two textboxes Params.Club_name, Params.RegionalName for ease let's call them txtClubname and txtRegionalName.
When the user enters the information into these two boxes so that [textclubname]=userclubname and [txtRegionalName]=userregionalname let's determine what you want to do...
Somewhere we have to have a table to work with...
Now this table either has to have fields in it named "userclubname" and "userregionalname" or you're trying to gather records where the information in the table field meets that requirement.
Case one:
tbl_example1
[PK] autonumber - primary key
[userclubname] - text(50) required, no duplicate
[userregionalname] - text(50) required, no duplicate - 'This code is written from memory, it has not
-
'been checked for typos against the complier
-
'sorry, not at a PC with Access or VB installed
-
'
-
Dim zdb As DAO.Database, zqrydef As DAO.QueryDef
-
Dim zsql as string
-
Dim zuserinput1 AS string, zuserinput2 AS string
-
'
-
'setup for the database
-
Set zdb = CurrentDB
-
'
-
'check to see if the query exsists
-
'qry_example
-
'and if so then remove it from the collection
-
For each zqrydef in zdb.querydefs
-
'
-
if lcase(zqrydef.name)="qry_example" then
-
zqrydef.delete "qry_example"
-
end if
-
next zqrydef
-
'
-
'now build the query for the selected fields:
-
zuserinput1 = me.txtclubname.value
-
'example user entered userclubname
-
'
-
zuserinput2 = me.txtregionalname.value
-
'example user entered userregionalname
-
'
-
'very simple select query, no wheres no whys
-
'just get the two fields from the table and
-
'show all records within the table tbl_example1
-
'
-
'NOTE the space appended in string!
-
zsql = "Select " & zuserinput1 & "," & _
-
"zuserinput2 & " " & _
-
"FROM tbl_example1;"
-
'
-
'Using our example this string should evaluate to:
-
'Select userclubname,
-
' userregionalname
-
'From tbl_example1;
-
-
'create the query (see why we searched first?)
-
'if you try to create a query with the same name
-
'access will have a tempertantrum
-
'
-
Set zqrydef = zdb.CreateQueryDef("qry_example", zsql)
-
'
-
'That's it... you can add code to open the query
-
'the user can open the query from the navigation pane
-
'you can use the query in the transfersheet method, etc..
-
'
-
'Clean UP - - Always a cleanup step
-
zdb.close
-
set zdb = nothing
-
set zqrydef = nothing
-
end sub
Case two:
tbl_example2
[PK] autonumber - primary key
[clubnames] - text(50) required, no duplicate
[regionalnames] - text(50) required, no duplicate
We're going to repeat some of the above code: - 'This code is written from memory, it has not
-
'been checked for typos against the complier
-
'sorry, not at a PC with Access or VB installed
-
'
-
Dim zdb As DAO.Database,
-
Dim zrs As DAO.recordset '<<<notice
-
Dim zsql as string
-
Dim zuserinput1 AS string, zuserinput2 AS string
-
'
-
'setup for the database
-
Set zdb = CurrentDB
-
'
-
'now build the query for the selected fields:
-
zuserinput1 = me.txtclubname.value
-
'example user entered userclubname
-
'
-
zuserinput2 = me.txtregionalname.value
-
'example user entered userregionalname
-
'
-
'very simple select query, no wheres no whys
-
'just get the two fields from the table and
-
'show all records within the table tbl_example2
-
'
-
'NOTE the space appended in string!
-
zsql = "Select * " & zuserinput1 & "," & _
-
"FROM tbl_example2 " & _
-
"WHERE(([clubnames] = '" & zuserinput1 & "')" & _
-
"AND ([regionalnames] = '" & zuserinput2 & "'));"
-
'Using our example this string should evaluate to:
-
'Select *
-
'From tbl_example2
-
'WHERE (([clubnames] = 'userclubname') AND
-
'(regionalnames] = 'userregionalname'));
-
'
-
'Now lets open a record set based on the sql string:
-
set zrs = zbd.openrecordset(zsql,dbOpenDynaset)
-
'
-
'That's it... you can add code to pull information out
-
'of the record set for display on the forms or whatever
-
'you desire (well... almost)
-
'
-
'Clean UP - - Always a cleanup step
-
zdb.close
-
set zdb = nothing
-
set zrs = nothing
-
end sub
As I said, I pulled all of the code for the two blocks out of my head... amazing how lazy I've gotten with the vba editor window... so there might be a syntax error.
-
z
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Joshua Russell |
last post by:
Hi,
Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of...
|
by: Adonai |
last post by:
Hi, I'm having an issue with this code that I'm writing, I'm curious as
to why the windows form label (lblTime) isn't getting updated with the
new variable when I use the timer. I made a blank form...
|
by: jhs |
last post by:
Hello,
I developping a .NET windows form application an need some help to create an
array of System.Windows.Forms.Label in order to be able to manage all of
them using index.
I'm trying to do...
|
by: Mike Bulava |
last post by:
I have created a base form that I plan to use throughout my application let
call the form form1. I have Built the project then add another form that
inherits from form1, I add a few panel controls...
|
by: jcrouse |
last post by:
Is there a quick and easy way to change the color of a label controls border
from the default black to white?
Thank you,
John
| |
by: Neil Wallace |
last post by:
Hi,
This is an odd one. I've been struggling to get "double click" to work well
for my controls.
The same event handler works perfectly for buttons, but not for labels.
Can anyone tell me...
|
by: Geraldine Hobley |
last post by:
Hello,
In my project I am inheriting several forms. However when I
inherit from a form and add additional subroutines and methods to my
inherited form I get all sorts of problems. e.g. I sometimes...
|
by: deekay |
last post by:
Im trying to update a database where our users have been
entering/editing all data using queries to now use forms instead. The
first step that I want to take is to convert the queries to forms in...
|
by: nave11 |
last post by:
How to add Context menu to a class derived from System.Windows.Forms.Label ?
This label will be dragged on a designer surface on runtime.
For example, to add a context menu with "Copy" and "Paste"...
|
by: Peter Larsen [] |
last post by:
Hi,
I have two questions related to the Label control.
How do i prevent the label from expand the canvas into 2 lines (word wrap)
??
At the moment i set AutoSize to false (to prevent the word...
|
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,...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |