473,569 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add a forms label to a query

489 Contributor
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.
Sep 12 '12 #1
11 5592
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
Sep 12 '12 #2
CD Tom
489 Contributor
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.
Sep 12 '12 #3
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
Sep 12 '12 #4
CD Tom
489 Contributor
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.
Sep 13 '12 #5
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.
Expand|Select|Wrap|Line Numbers
  1. SELECT PK, [Forms]![FormName]![LabelName].[Caption] AS LabelCaption
  2. FROM someTable
With that, if my label caption is Name: and I have 3 records in the table, my results would be:
Expand|Select|Wrap|Line Numbers
  1. 1 Name:
  2. 2 Name:
  3. 3 Name:
Sep 13 '12 #6
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:
Expand|Select|Wrap|Line Numbers
  1. SELECT PK, 
  2.    [Forms]![FormName]![TextBoxName].[Value] 
  3.   AS TextBoxValue 
  4. FROM someTable 
-z
Attached Images
File Type: jpg byte_frm_example.jpg (114.1 KB, 2018 views)
Sep 13 '12 #7
CD Tom
489 Contributor
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
Expand|Select|Wrap|Line Numbers
  1. (A cut and paste may not work on this )
  2. Set ExtractParm = db.QueryDefs("Extractparm")
  3. ExtractParm.SQL = 
  4.    "SELECT [forms]![Params]![Match4].[Caption]
  5.    as EventName, 
  6.    Params.Club_name, Params.RegionalName, 
  7.    Params.WildbunchStages, Params.Wildbunchdate,
  8.    Params.RankPointsWB, Params.TotalTimeWB,
  9.    Params.RankbyClassWB, Params.WBShotPoint, 
  10.    Params.MisseTime, Params.PenaltiesTime,    
  11.    Params.BonusstageWB1, Params.BonusstageWB2," & _
  12.    "Params.BonusstageWB3, Params.BonusstageWB4, 
  13.    Params.BonusstageWB5, Params.BonusstageWB6,    
  14.    Params.BonusstageWB7, Params.BonusstageWB8, 
  15.    Params.BonusstageWB9, Params.BonusstageWB10, 
  16.    Params.BonusstageWB11, Params.BonusstageWB12," & _
  17.    "Params.MatchDQTotal, Params.StageDQTotal,
  18.    Params.DNFTotal, Params.StageDQTargets,
  19.    Params.TargetPlus 
  20. FROM Params"
When I run the query it ask for a value to enter in the forms field.
Sep 13 '12 #8
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
Sep 14 '12 #9
CD Tom
489 Contributor
I guess I'll try and change those labels to textboxs and give that a try. Thanks for you advice and help.
Sep 14 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2273
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 master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with...
0
1545
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 with only the timer and the label, and it works fine, is there something else I need to do with the threads to get this to work? I'm a bit lost...
3
32479
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 this in form_load void: System.Windows.Forms.Label labelArray = new System.Windows.Forms.Label; for (i=1;i<91;i++)
7
2462
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 each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through...
31
7167
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
3
2408
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 why not? Below is an working VB.Net example to illustrate what I mean.
3
2362
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 get MyVarialble is not declared errors when the variable is quite clearly declared, when I change it to public and then back again to private the...
2
3186
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 datasheet view so that they look exactly the same. I just want to know whether it is better to bind the forms record source to the queries or to a...
0
965
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" to a Label or TextBox? I have tried adding the context menu code in designer , and i can get the context menu at design time , but cannot see that...
11
11479
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 wrap from happening) and Anchor to Left, Right (to enable the with autosize). How do i prevent a tool-tip from happening if the text is to large...
0
7612
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...
0
7922
Oralloy
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. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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...
0
6281
agi2029
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...
0
5218
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.