473,698 Members | 2,403 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
11 5606
CD Tom
489 Contributor
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.
Sep 14 '12 #11
zmbd
5,501 Recognized Expert Moderator Expert
CD Tom,
Don't give up just yet.
Let's look at the two textboxes Params.Club_nam e, Params.Regional Name 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]=userregionalna me 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 "userclubna me" and "userregionalna me" 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
[userregionalnam e] - text(50) required, no duplicate

Expand|Select|Wrap|Line Numbers
  1. 'This code is written from memory, it has not
  2. 'been checked for typos against the complier
  3. 'sorry, not at a PC with Access or VB installed
  4. '
  5. Dim zdb As DAO.Database, zqrydef As DAO.QueryDef
  6. Dim zsql as string
  7. Dim zuserinput1 AS string, zuserinput2 AS string 
  8. '
  9. 'setup for the database
  10. Set zdb = CurrentDB
  11. '
  12. 'check to see if the query exsists
  13. 'qry_example
  14. 'and if so then remove it from the collection
  15. For each zqrydef in zdb.querydefs
  16.    '
  17.    if lcase(zqrydef.name)="qry_example" then
  18.       zqrydef.delete "qry_example"
  19.    end if
  20. next zqrydef
  21. '
  22. 'now build the query for the selected fields:
  23. zuserinput1 = me.txtclubname.value
  24. 'example user entered userclubname
  25. '
  26. zuserinput2 = me.txtregionalname.value
  27. 'example user entered userregionalname
  28. '
  29. 'very simple select query, no wheres no whys
  30. 'just get the two fields from the table and
  31. 'show all records within the table tbl_example1
  32. '
  33. 'NOTE the space appended in string!
  34. zsql = "Select " & zuserinput1 & "," & _
  35.        "zuserinput2 & " " & _
  36.        "FROM tbl_example1;"
  37. '
  38. 'Using our example this string should evaluate to:
  39. 'Select userclubname,
  40. '   userregionalname
  41. 'From tbl_example1;
  42.  
  43. 'create the query (see why we searched first?)
  44. 'if you try to create a query with the same name
  45. 'access will have a tempertantrum
  46. '
  47. Set zqrydef = zdb.CreateQueryDef("qry_example", zsql)
  48. '
  49. 'That's it... you can add code to open the query
  50. 'the user can open the query from the navigation pane
  51. 'you can use the query in the transfersheet method, etc..
  52. '
  53. 'Clean UP - - Always a cleanup step
  54. zdb.close
  55. set zdb = nothing
  56. set zqrydef = nothing
  57. 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:
Expand|Select|Wrap|Line Numbers
  1. 'This code is written from memory, it has not
  2. 'been checked for typos against the complier
  3. 'sorry, not at a PC with Access or VB installed
  4. '
  5. Dim zdb As DAO.Database, 
  6. Dim zrs As DAO.recordset '<<<notice
  7. Dim zsql as string
  8. Dim zuserinput1 AS string, zuserinput2 AS string 
  9. '
  10. 'setup for the database
  11. Set zdb = CurrentDB
  12. '
  13. 'now build the query for the selected fields:
  14. zuserinput1 = me.txtclubname.value
  15. 'example user entered userclubname
  16. '
  17. zuserinput2 = me.txtregionalname.value
  18. 'example user entered userregionalname
  19. '
  20. 'very simple select query, no wheres no whys
  21. 'just get the two fields from the table and
  22. 'show all records within the table tbl_example2
  23. '
  24. 'NOTE the space appended in string!
  25. zsql = "Select * " & zuserinput1 & "," & _
  26.        "FROM tbl_example2 " & _
  27.        "WHERE(([clubnames] = '"  & zuserinput1 & "')" & _
  28.        "AND ([regionalnames] = '" & zuserinput2 & "'));"
  29. 'Using our example this string should evaluate to:
  30. 'Select *
  31. 'From tbl_example2
  32. 'WHERE (([clubnames] = 'userclubname') AND
  33. '(regionalnames] = 'userregionalname'));
  34. '
  35. 'Now lets open a record set based on the sql string:
  36. set zrs = zbd.openrecordset(zsql,dbOpenDynaset)
  37. '
  38. 'That's it... you can add code to pull information out
  39. 'of the record set for display on the forms or whatever
  40. 'you desire (well... almost)
  41. '
  42. 'Clean UP - - Always a cleanup step
  43. zdb.close
  44. set zdb = nothing
  45. set zrs = nothing
  46. 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
Sep 14 '12 #12

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

Similar topics

3
2285
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 the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference...
0
1550
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 here. Thanks in advance -- Aaryn // Code Start
3
32490
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
2471
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 the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
31
7225
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
2417
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
2371
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 error goes away!!! Also I get lots of member not found errors, these however don't stop me from...
2
3192
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 sql statement that would include the relevant tables and fields. Please advise thanks
0
991
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 at runtime. if any other way its possible , please let me know.
11
11494
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 to fit in
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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,...
0
9169
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7738
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4371
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...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.