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. - Private Sub cmbLocalOffice_AfterUpdate()
-
'Filter frmAll based on search criteria
-
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;"
-
-
Forms!frmMain.Caption = "Search Results"
-
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?
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
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: - Me![cmbLocalOffice].Column(n)
where n is a Zero based Column Number.
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?
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.
I corrected the code above. I updated the code to something easier to me that may work better.
Combo box Row Source here: - 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" 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.
This is what I got when I changed the ColumnWidth to "2"
Same outcome. 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.
NeoPa 32,556
Expert Mod 16PB
Here's an example you may want to use :
.RowSource = - SELECT [LocalOffice],[LocalOfficeID]
-
FROM [tblLocalOffice]
-
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.
I took your advise on the RowSource. - SELECT tblLocalOffice.LocalOffice, tblLocalOffice.LocalOfficeID
-
FROM tblLocalOffice
-
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.
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).
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 : - [Forms]![frmMain]![frmAll]![LocalOfficeID] doesn't appear to be the name used for the control I assume we're talking about.
- 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 : - 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 (tblAirwatch.LocalOfficeID=Nz([Forms]![frmMain]![frmAll]![cmbLocalOffice],tblAirwatch.LocalOfficeID))
-
ORDER BY tblLocalOffice.LocalOffice
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.
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.
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. - Private Sub cmbLocalOffice_AfterUpdate()
-
Dim strSQL As String
-
Dim dbs_curr As Database
-
Dim records As Recordset
-
-
Set dbs_curr = CurrentDb
-
-
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;"
-
-
-
'Change the caption on frmMain
-
Forms!frmMain.Caption = "Search Results"
-
-
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.
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! - Dim strSQL As String
-
-
strSQL = "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;"
then you can use a debug.pring to find the issue....
You then use it in line 8 as: - Forms!frmMain!frmAll.Form.RecordSource = strSQL
Also, are you refering to a subform recordsource?
I suspect it is : - " [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 ?
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
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 ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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...
|
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...
|
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...
|
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...
| |