473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I get a name to display instead of a value?

anoble1
245 128KB
I have a database I am making. I have 1 table with data.
I am making a "limit" that will limit records based on a combobox. When I select the table column list it has all the names. When I hit limit it goes through here.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbLocalOffice_AfterUpdate()
  2. 'Filter frmAll based on search criteria
  3. Forms!frmMain!frmAll.Form.RecordSource = "SELECT tblAirwatch.ID, tblLocalOffice.LocalOffice, tblAirwatch.Region, tblAirwatch.Address, tblAirwatch.City, tblAirwatch.State, tblAirwatch.ZipCode, tblAirwatch.iPadSerialNumber, tblAirwatch.AirwatchName, tblAirwatch.PrinterBluetoothPin FROM tblAirwatch INNER JOIN tblLocalOffice ON tblAirwatch.LocalOfficeID = tblLocalOffice.LocalOfficeID WHERE (((tblLocalOffice.LocalOffice)=[Forms]![frmMain]![frmAll]![LocalOfficeID].value)) ORDER BY tblLocalOffice.LocalOffice;"
  4.  
  5. Forms!frmMain.Caption = "Search Results"
  6. End Sub
the cmbLocalOffice.Value has a value of "1" instead of the Office name. I am missing something easy here. Does the code need to be the .value since I am getting text and not a number?
Jan 3 '14 #1

✓ answered by NeoPa

Z has a good point about working out string values into string variables before using them if you are debugging. It does make life so much easier for all.

I hear you that the problem was in the fact that you set a .ControlSource property value when it should have been left empty.

Nevertheless, rather than setting the whole .RecordSource again every time the ComboBox is updated, it would make a lot more sense simply to set the .Filter and .FilterOn properties. That's what they're there for. Simplifies not only the code, but also any work developing or maintaining it ;-)

17 1470
ADezii
8,834 Expert 8TB
Assuming cmbLocalOffice is Bound to your Table, a Query, or an SQL Statement based on the Table, you are more than likely reading the Value of the 'Bound' Column. The actual Value you are looking for resides in another Column other than the 'Bound' one. The Syntax for referring to a Column Value within a Combo Box selection is:
Expand|Select|Wrap|Line Numbers
  1. Me![cmbLocalOffice].Column(n)
where n is a Zero based Column Number.
Jan 3 '14 #2
anoble1
245 128KB
if you see my attachments, my cmblocaloffice is a combo box on my screen with the selections. on the left is the list i want to limit based on what i select. On screenshot Help3.jpg you see that it is finding the value 1 which is right, but why does it change my screenshot help4.jpg to say a #1 instead of Albany, and it still does not limit it?

On your statement, does that need to be coded like that? Or a form property?



Attached Images
File Type: jpg help.jpg (30.8 KB, 325 views)
File Type: jpg help2.jpg (15.4 KB, 334 views)
File Type: jpg help4.jpg (26.5 KB, 334 views)
Jan 3 '14 #3
ADezii
8,834 Expert 8TB
There appears to be some missing Code after GCriteria is established and Local Office is populated, kindly Post it. Also, post the Row Source for the Combo Box.
Jan 3 '14 #4
anoble1
245 128KB
I corrected the code above. I updated the code to something easier to me that may work better.

Combo box Row Source here:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblLocalOffice.LocalOfficeID, tblLocalOffice.LocalOffice FROM tblLocalOffice ORDER BY tblLocalOffice.LocalOffice;



Please see this too.
When I limit the selections for "Americus" it prompts me to enter in the name for some reason. So, I typed in Americus, and the limit worked! but, my first Local Office turned from "Albany" to "2"



Attached Images
File Type: jpg help5.jpg (44.5 KB, 354 views)
File Type: jpg help6.jpg (59.0 KB, 283 views)
File Type: jpg help7.jpg (19.2 KB, 287 views)
Jan 3 '14 #5
NeoPa
32,556 Expert Mod 16PB
Look at your .ColumnWidths property. The value shown will always be the leftmost column in your list with any width. Either put the column you want shown as the first one, or make sure all columns to the left of it have width of zero (0).

This is not connected to the bound column, which is set in a different property - .BoundColumn.
Jan 3 '14 #6
anoble1
245 128KB
This is what I got when I changed the ColumnWidth to "2"
Same outcome.

Attached Images
File Type: jpg help8.jpg (26.4 KB, 273 views)
Jan 3 '14 #7
NeoPa
32,556 Expert Mod 16PB
There are three properties that are associated with width.

.Width
.ListWidth
.ColumnWidths


The one I drew to your attention was not misspelled. It is not designed to be used as a single item when multiple columns are used, but as a list.

If this is, indeed, the property you set to "2" then we would expect that to give the result you saw. It's certainly not what I suggested.

If you revisit my previous post and follow the information contained therein more carefully you should find a way that suits you.
Jan 3 '14 #8
NeoPa
32,556 Expert Mod 16PB
Here's an example you may want to use :
.RowSource =
Expand|Select|Wrap|Line Numbers
  1. SELECT   [LocalOffice],[LocalOfficeID]
  2. FROM     [tblLocalOffice]
  3. ORDER BY [LocalOffice]
.ColumnWidths = "2;.5"
.BoundColumn = 2

There are other possibilities depending on how you want it, but this is at least an example of one of them that might help.
Jan 3 '14 #9
anoble1
245 128KB
I took your advise on the RowSource.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblLocalOffice.LocalOffice, tblLocalOffice.LocalOfficeID
  2. FROM tblLocalOffice
  3. ORDER BY tblLocalOffice.LocalOffice;

Example - If I type in the second Office in the list "Alma", it will find and limit now! However, it changes the 1st records name to "Alma" too, instead of "Albany". When I did the BoundColumn, it limited my results, but still is changing my first record in the list to what I typed in. Why is that box coming up anyway?

I have noticed. Whenever I select something from the cmbLocalOffice it automatically changes my 1st record (Albany) on the main screen or search results to match what I selected. Example, if in the cmbLocalOffice I select "Americus" the (Albany) on the main screen will change to "Americus" and there will be 2 of them. just the Local Office name.

Attached Images
File Type: jpg help9.jpg (43.6 KB, 346 views)
Jan 3 '14 #10
ADezii
8,834 Expert 8TB
As previously stated, I still think that part of the problem is in the remainder of the Code (after Criteria is set) in the cmbLocalOffice_AfterUpdate() Event, that you posted a Graphic of in Post# 3, 3rd Graphic. My eyes cannot decipher this, maybe NeoPa's can since he is a lot younger. (LOL).
Jan 4 '14 #11
NeoPa
32,556 Expert Mod 16PB
It seems you are looking to provide a filter. Your earlier terminology confused me thoroughly. I assumed you were working with a control in the detail section of your form on a per-record basis.

For filtering, you can look at Example Filtering on a Form to get a better background understanding of the issue. In this case, things are somewhat clearer now, but still quite confusing when I try to understand what you're actually trying to achieve.

By reverse-engineering the SQL of your first post I have a clue as to what data is showing and from where. So, the form is basically showing the contents of [tblAirwatch] but shows the Office Description ([LocalOffice]) from [tblLocalOffice]. That I get.

It appears there are two issues with the SQL in the code of your OP though :
  1. [Forms]![frmMain]![frmAll]![LocalOfficeID] doesn't appear to be the name used for the control I assume we're talking about.
  2. Assuming some sort of basic consistency of naming in your project, you're comparing the name of the office on one side with the ID on the other.

An alternative way to filter is to use a reference in the SQL to the control you want to filter on. In the example SQL below I've assumed the name of your control is cmbLocalOffice and that it returns an ID value rather than a name/text one :
Expand|Select|Wrap|Line Numbers
  1. SELECT   tblAirwatch.ID
  2.        , tblLocalOffice.LocalOffice
  3.        , tblAirwatch.Region
  4.        , tblAirwatch.Address
  5.        , tblAirwatch.City
  6.        , tblAirwatch.State
  7.        , tblAirwatch.ZipCode
  8.        , tblAirwatch.iPadSerialNumber
  9.        , tblAirwatch.AirwatchName
  10.        , tblAirwatch.PrinterBluetoothPin
  11. FROM     [tblAirwatch]
  12.          INNER JOIN
  13.          [tblLocalOffice]
  14.   ON     tblAirwatch.LocalOfficeID = tblLocalOffice.LocalOfficeID
  15. WHERE    (tblAirwatch.LocalOfficeID=Nz([Forms]![frmMain]![frmAll]![cmbLocalOffice],tblAirwatch.LocalOfficeID))
  16. ORDER BY tblLocalOffice.LocalOffice
Jan 4 '14 #12
NeoPa
32,556 Expert Mod 16PB
ADezii
"My eyes cannot decipher this, maybe NeoPa's can since he is a lot younger. (LOL)."

I wish. That's not legible (to anyone I suspect). I increased the zoom right up, but the quality is far too poor for comfortable reading even when it's big. The text is all just very fuzzy. Posting code in a graphic is never a good idea. Posting it within the provided [CODE] tags, on the other hand, is.
Jan 5 '14 #13
zmbd
5,501 Expert Mod 4TB
anoble1:
What is being asked is that post the text of the code and not screenshots.
You can cut and paste the script from the editor window, please format it using the [CODE/] button.
Jan 5 '14 #14
anoble1
245 128KB
Sorry for the confusion. I though I would code it an "easier" way that I may could understand better, tagging on your suggestions. let me try and clear up confusion that I have mode above. As of now. below is the code on the "AfterUpdate" on the filter that I attempted to make.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbLocalOffice_AfterUpdate()
  2. Dim strSQL As String
  3. Dim dbs_curr As Database
  4. Dim records As Recordset
  5.  
  6. Set dbs_curr = CurrentDb
  7.  
  8. Forms!frmMain!frmAll.Form.RecordSource = "SELECT tblAirwatch.LocalOffice, tblAirwatch.Region, tblAirwatch.Address, tblAirwatch.City, tblAirwatch.State, tblAirwatch.ZipCode, tblAirwatch.iPadSerialNumber, tblAirwatch.AirwatchName, tblAirwatch.PrinterBluetoothPin FROM tblAirwatch INNER JOIN tblLocalOffice ON tblAirwatch.LocalOfficeID = tblLocalOffice.LocalOfficeID WHERE (((tblLocalOffice.LocalOffice)=[Forms]![frmMain]![frmAll]![cmbLocalOffice].value)) ORDER BY tblAirwatch.LocalOffice;"
  9.  
  10.  
  11. 'Change the caption on frmMain
  12. Forms!frmMain.Caption = "Search Results"
  13.  
  14. End Sub
@NeoPa
Don't know if i used your code correctly. I commented my line out and used yours. The filter did not work on mine. But let me do some reading on the link you posted and see what I'm missing.
Jan 6 '14 #15
zmbd
5,501 Expert Mod 4TB
To put it mildly, Post#15 Code-Block-Line8 - YUCK!!!!

How can you posibly know if your string is resolving correctly... you can't

Try building the SQL String FIRST!
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "SELECT tblAirwatch.LocalOffice, tblAirwatch.Region" & _
  4.    ", tblAirwatch.Address, tblAirwatch.City" & _
  5.    ", tblAirwatch.State, tblAirwatch.ZipCode" & _
  6.    ", tblAirwatch.iPadSerialNumber, tblAirwatch.AirwatchName" & _
  7.    ", tblAirwatch.PrinterBluetoothPin" & _
  8.    " FROM tblAirwatch INNER JOIN tblLocalOffice " & _
  9.    " ON tblAirwatch.LocalOfficeID = tblLocalOffice.LocalOfficeID" & _
  10.    " WHERE (((tblLocalOffice.LocalOffice)=" & _
  11.    " [Forms]![frmMain]![frmAll]![cmbLocalOffice].value))" & _
  12.    " ORDER BY tblAirwatch.LocalOffice;"
then you can use a debug.pring to find the issue....

You then use it in line 8 as:
Expand|Select|Wrap|Line Numbers
  1. Forms!frmMain!frmAll.Form.RecordSource = strSQL
Also, are you refering to a subform recordsource?


I suspect it is :
Expand|Select|Wrap|Line Numbers
  1. " [Forms]![frmMain]![frmAll]![cmbLocalOffice].value))" &
Because the way that is written, you're not getting the value returned from that control, you are getting the litteral string of "[Forms]![frmMain]![frmAll]![cmbLocalOffice].value))"
Also is this a string or a numeric value being returned by cmbLocalOffice ?
Jan 6 '14 #16
anoble1
245 128KB
Greetings NeoPa, ADezii who always help me and zmbd. Check this out. On the cmbLocalOffice I had a control source on it. I should have left it blank with no control source. I thought it was my SQL error. I un-bound the control source and everything worked fine.

Thanks guys
Jan 6 '14 #17
NeoPa
32,556 Expert Mod 16PB
Z has a good point about working out string values into string variables before using them if you are debugging. It does make life so much easier for all.

I hear you that the problem was in the fact that you set a .ControlSource property value when it should have been left empty.

Nevertheless, rather than setting the whole .RecordSource again every time the ComboBox is updated, it would make a lot more sense simply to set the .Filter and .FilterOn properties. That's what they're there for. Simplifies not only the code, but also any work developing or maintaining it ;-)
Jan 7 '14 #18

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

Similar topics

5
by: bryan.com | last post by:
There must be a way. I'm making a selection from a drop-down list that had an ID number as the value and displays a text field. After submitting the data to the database I am sending an email and...
5
by: aad | last post by:
Hi, I would like to display a label twice on one page. Duplicate the label result in the error "The ID 'xxxxx' is already used by another control" Ok I understand that it can bind to only...
3
by: Nofi | last post by:
Hello, I'm trying to fill my combobox per code, not with a DataSet because I want to have an empty row in it and this wasn't possible when working with a DataSet. The fill works fine, but when I...
2
by: HarisHohkl | last post by:
Hi, I've this function in a class to update the total value.but when i try to remove the these row highlight in Bold it crash, what should i do???? void display_total_value() { double...
0
by: keithsimpson3973 | last post by:
Does anyone know if it is possible to display the value of a date picker control on a vb6 form that the user selected on an access report? I am using vb6 to display a report selection and it has a...
28
by: ajos | last post by:
hi frnds, im doing a project in struts... my project specifications- struts1.1,tomcat5.5.23,eclipse3.2. the situation--> i have a form where i have a html <select> attribute in the <option>...
2
by: jeenajos | last post by:
Hi all, How can we display a value in message box in Asp.net. Now im using the script for displaying strings. Response.Write("<script>alert('OK')</script>") Along with this string i...
10
by: lakki63 | last post by:
hi all.. I m new to html....In my html page i place one multiline textbox...My query is when i enter data into textbox and click submit button..i have to display dat message in below to the...
24
by: MNNovice | last post by:
I am trying to display a value from the sub form on to the main form. It's not a calculated data, just plain text. This is what I attempted without success. 1. Created a text box called...
0
by: safuta | last post by:
i need help here. how do i display checkbox value from my database MS access in a visual basic 6 form? i hv 2 checkbox in my form, which are Available and Not Available. if the value is yes, i want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
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...
0
tracyyun
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 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.