473,385 Members | 1,693 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,385 software developers and data experts.

Limit field values with a combobox on a subform

Hello!

I have a question I've been working on for a few days now and I can't find a solution. I hope there is someone that has the answer :)

I'm using Access 2003 in win XP. I have a main form called "MulitLineView", that has a subform called "subLinelistView". In the main form's "Form_Open" event I use a query to open the contents of a table for editing in the subform in datasheet mode like this:
Expand|Select|Wrap|Line Numbers
  1. Set qdf = db.CreateQueryDef(strQueryName, strQuery)
  2. subLinelistView.SourceObject = "Query." & strQueryName
This all works fine, the subform shows the proper fields. I'm also applying locks to fields (using a combobox which I hide) with:
Expand|Select|Wrap|Line Numbers
  1. Forms("MultiLineView").Controls("subLinelistView").Form.Controls(cmbMayNotEdit.Column(0, intCounter)).Properties("Locked") = True
This works fine too.

My question is: How can I make it so that for some columns, the values which can be entered in the field are limited by a combobox?
The rowsources for the comboboxes should be queries which I want to provide in the code for each column. I've been trying to find the right control property, I tried things like:
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT plant_abbr FROM Plants"
  2. Forms("MultiLineView").Controls("subLinelistView").Form.Controls("Plant_abbr").RowSource = strQuery
and
Expand|Select|Wrap|Line Numbers
  1. Forms("MultiLineView").Controls("subLinelistView").Form.Controls("Plant_abbr").Properties("RowSource") = strQuery
but in runtime I always get an error msg saying the object doesn't have that property.

Can anyone help me pull this off? Any help is greatly appreciated! :)
Jul 11 '08 #1
11 4124
puppydogbuddy
1,923 Expert 1GB
My question is: How can I make it so that for some columns, the values which can be entered in the field are limited by a combobox?[/u]
The rowsources for the comboboxes should be queries which I want to provide in the code for each column. I've been trying to find the right control property, I tried things like:
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT plant_abbr FROM Plants"
  2. Forms("MultiLineView").Controls("subLinelistView").Form.Controls("Plant_abbr").RowSource = strQuery
and
Expand|Select|Wrap|Line Numbers
  1. Forms("MultiLineView").Controls("subLinelistView").Form.Controls("Plant_abbr").Properties("RowSource") = strQuery
but in runtime I always get an error msg saying the object doesn't have that property.

Can anyone help me pull this off? Any help is greatly appreciated! :)
try this syntax, assuming plan_abbr is your combo box:
see this link:
http://www.mvps.org/access/forms/frm0031.htm

Expand|Select|Wrap|Line Numbers
  1. Forms!MultiLineView!subLinelistView.Form![Plant_abbr].RowSource = strQuery
Or better:
Expand|Select|Wrap|Line Numbers
  1. Me!subLinelistView.Form![Plant_abbr].RowSource = strQuery
Jul 12 '08 #2
try this syntax, assuming plan_abbr is your combo box:
see this link:
http://www.mvps.org/access/forms/frm0031.htm

Expand|Select|Wrap|Line Numbers
  1. Forms!MultiLineView!subLinelistView.Form![Plant_abbr].RowSource = strQuery
Or better:
Expand|Select|Wrap|Line Numbers
  1. Me!subLinelistView.Form![Plant_abbr].RowSource = strQuery
Thanks for your reply!
I tried the syntax you provided, but I get the same message. My Access is in Dutch but the message should translate to: "This property or method is not supported by this object".

Maybe the problem lies here: I'm opening the query in the subform that is blank. I haven't put any controls in the subform, because I'm using a query as sourceobject. This query is generated is run-time and can be different every time, since I've made it so that the user is able to select which columns to view.
The query I use is:
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT " & strColumns & " FROM " & CurLinelistTN & IIf(Forms!MainMenuNew.cmbSelectPlant.Value = "All", "", " WHERE [Plant_abbr] = '" & Forms!MainMenuNew.cmbSelectPlant.Value & "' ") & IIf(strSortBy = "", "", " ORDER BY " & strSortBy & "") & ";"
This query works fine though, it shows what it's supposed to every time.

But I don't know what kind of controls are created for a query in datasheet view. Is there a way to control this? I've tried to get the controltype with:
Expand|Select|Wrap|Line Numbers
  1. strControlType = Me!subLinelistView.Form![Plant_abbr].ControlType
But that just returns a "116" every time with any column I put in in the place of "Plant_abbr". I don't know what that '116' means. As far as I have been able to find out, the "ControlType" property should return something like "acTextBox" or "acComboBox".

Is there any way that I can choose what type of controls are created to show the fields when I open the query? So that I can have comboboxes for certain fields, where I can set the rowsource?
Jul 12 '08 #3
puppydogbuddy
1,923 Expert 1GB
What is Plant_abbr.....a textbox? and is it on the main form or the subform?

If you are executing your code from the subform:
Change this:
strControlType = Me!subLinelistView.Form![Plant_abbr].ControlType

To this:
strControlType = Me![Plant_abbr].ControlType


And re this:
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT " & strColumns & " FROM " & CurLinelistTN & IIf(Forms!MainMenuNew.cmbSelectPlant.Value = "All", "", " WHERE [Plant_abbr] = '" & Forms!MainMenuNew.cmbSelectPlant.Value & "' ") & IIf(strSortBy = "", "", " ORDER BY " & strSortBy & "") & ";"
You can refer to columns this way ( I used column 0 for example) :
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT " & strColumns & " FROM " & CurLinelistTN & IIf(Forms!MainMenuNew.cmbSelectPlant.Value = "All", "", " WHERE [Plant_abbr] = '" & Forms!MainMenuNew.cmbSelectPlant.Column(0) & "' ") & IIf(strSortBy = "", "", " ORDER BY " & strSortBy & "") & ";"
Jul 12 '08 #4
Plant_abbr is a column name. It's one of the columns that can be selected in the query that is displayed in the subform. I'm running all code from the main form. The subform is completely blank, it doesn't have anything on it. I just use it to open the query on. But we can forget about the big query, I just showed it to explain that the query I display in the subform has a lot of variables, but that's all working fine. Maybe I elaborated too much by showing that.

I think the syntax is OK, it's just that I dont' know which properties to use. I know that I'm getting to the controls of the query that's opened in the subform, since I can lock columns.

Maybe I can explain it better with a simplified example. Let's forget all the above and go with this: I have a table called "Linelist_current" which has 10 columns of data. I have a main form "MultiLineView", which has a subform "subLinelistView". The subform is completely blank, nothing on it. All code is run from "MultiLineView". Let's say I do the following:
Expand|Select|Wrap|Line Numbers
  1. Dim db as DAO.Database
  2. Dim qdf as DAO.QueryDef
  3. Dim strQueryName, strQuery as String
  4. Set db = currentDb
  5. strQueryName = "MyLinelistView"
  6. strQuery = "SELECT IDLine, Plant_abbr, LineSize FROM Linelist_current WHERE Plant_abbr = 'POLY';"
  7. Set qdf = db.CreateQueryDef(strQueryName, strQuery)
  8. subLinelistView.SourceObject = "Query." & strQueryName
  9. Me!subLinelistView.Form.Controls("IDLine").Locked = True
Now I have opened the query on the subform in datasheet view. I see 3 columns with data: IDline, Plant_abbr, and LineSize. I can edit everything except for the IDLine column, since I locked that one. Now I want to make sure that the values that can be entered in the "LineSize" column are limited by a combobox. The source of this combobox has to be a table called "Size", that has just 1 column with numbers. I would want to do something like:
Expand|Select|Wrap|Line Numbers
  1. Me!subLinelistView.Form.Controls("LineSize").RowSourceType = "Table/Query"
  2. Me!subLinelistView.Form.Controls("LineSize").RowSource = "SELECT * FROM Size"
But this doesnt work, I get the error message saying that the property or method is not supported by the object.

How do I go about making a combobox for the "LineSize" column?
Jul 12 '08 #5
puppydogbuddy
1,923 Expert 1GB
Here is a basic example of the way I set up my comboboxes in code:
Expand|Select|Wrap|Line Numbers
  1. Dim cboType As ComboBox
  2.  
  3. Set cboType = Me!cboLineSize
  4.         With cboType
  5.             .RowSourceType = "Table/Query"
  6.             .RowSource = "SELECT *  From Size"
  7.         End With
  8.  
  9. Me!cboLineSize.Locked = True
  10.  
  11. Set cboType = Nothing
Jul 12 '08 #6
First of all, thank you for your replies I appreciate your effort to help me!
Maybe I haven't been clear on this. This form is part of an access application that has around 30 users, editing a table that has around 64 columns (no..it can not be normalized :p). Each user is able to customize a "view" of the table, specifying which columns to view (anywhere from 1 to 64), in which order, and by which columns to sort by. I use these views, which are stored in a table, to create the queries that get data from the table, at run-time, and I delete the query when the form closes. So I'm dealing with the results of a temporary query. Because the query is different every time, I don't use a form with a set query as recordsource, but I assign the results to a blank subform. So I'd like to know how I can change the properties of this query result, to set a rowsource for certain columns, so that they become comboboxes.
Is there some way to link a combobox created in code to the query results?
Jul 12 '08 #7
puppydogbuddy
1,923 Expert 1GB
You have complete flexibility to set the combobox properties in the example I gave you above. Here is a more detailed example excerpted from one of my applications. In the example below, a specific limited group of accounts is displayed for selection in a subform combobox depending on the the report and account that the user selected from 2 comboboxes on the main form. The code below is used in conjunction with a button click event that makes the combobox visible. There are many ways to do it ....you have complete control over which properties you want to set for the combobox. this is the way I chose to do it for my application.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)    ' subform open event
  2. On Error GoTo Error_Routine
  3.  
  4.         'Hide the reclass combo box until reclass button clicked (button click event)
  5.         Me!cboAcctClassX.Visible = False
  6.  
  7.         'deselect any checkboxes that are ticked (initialize all checkboxes as unchecked)
  8.         btnDeselect_Click
  9.  
  10.         Set cboType = Me!cboAcctClass
  11.         With cboType
  12.             .RowSourceType = "Table/Query"
  13.             If Parent![cboReport].Column(2) = "XXXReportXXXX" Then
  14.                 Select Case Parent!cboReport.Column(1)
  15.                     Case 20, 22            'balance sheet reports                               
  16.                         .RowSource = "SELECT * From OneofMyTables"  
  17. Case Else                                  'revenue & expense reports
  18.                         .RowSource = "SELECT * From AnotherOneOfMyTables" 
  19.                 End Select
  20.             End If
  21.         End With
  22.  
  23. Set cboType = Nothing
  24.  
  25. Me!cboAcctClass.Locked = True
  26.  
  27. Exit_Continue:
  28.         Exit Sub
  29. Error_Routine:
  30.         MsgBox "Error# " & Err.Number & " " & Err.Description
  31.         Resume Exit_Continue
  32.  
  33. End Sub
Jul 12 '08 #8
I didn't your previous post well enough the last time, my apologies! That's because I'm so stressed out and tired from trying so many things haha. So I tried your example. After opening the query I create a combobox, asssign a column to it, then set rowsourcetype and rowsource ("Plant_abbr" is the name of a column) :

Expand|Select|Wrap|Line Numbers
  1. Dim cmbTest As ComboBox
  2. Set cmbTest = Me!subLinelistView.Form![Plant_abbr]
  3. With cmbTest
  4.     .RowSourceType = "Table/Query"
  5.     .RowSource = "SELECT Plant_abbr FROM Plants"
  6. End With
But at this line: .RowSourceType = "Table/Query" I get an error message saying something like "the expression contains an invalid referral to the RowSourceType property". I'm running this code form "MultiLineView" (the parentform of "subLinelistView")

I wonder what kind of controls are created when the query opens in the subform. Because to me it sounds like it's saying that the control for the "Plant_abbr" column is not a combobox. Is there any way to control that? Or maybe I have the syntax wrong?
Jul 13 '08 #9
puppydogbuddy
1,923 Expert 1GB
I didn't your previous post well enough the last time, my apologies! That's because I'm so stressed out and tired from trying so many things haha. So I tried your example. After opening the query I create a combobox, asssign a column to it, then set rowsourcetype and rowsource ("Plant_abbr" is the name of a column) :

Expand|Select|Wrap|Line Numbers
  1. Dim cmbTest As ComboBox
  2. Set cmbTest = Me!subLinelistView.Form![Plant_abbr]
  3. With cmbTest
  4.     .RowSourceType = "Table/Query"
  5.     .RowSource = "SELECT Plant_abbr FROM Plants"
  6. End With
But at this line: .RowSourceType = "Table/Query" I get an error message saying something like "the expression contains an invalid referral to the RowSourceType property". I'm running this code form "MultiLineView" (the parentform of "subLinelistView")

I wonder what kind of controls are created when the query opens in the subform. Because to me it sounds like it's saying that the control for the "Plant_abbr" column is not a combobox. Is there any way to control that? Or maybe I have the syntax wrong?
Your syntax is wrong. Based on the above info and your prior postings your combobox is named cmbSelectPlant and is on the subform, thus your code should be launched from the <<subform>> and should look something like this:

Expand|Select|Wrap|Line Numbers
  1. Dim cmbTest As ComboBox
  2. Set cmbTest = Me!cboSelectPlant
  3. With cmbTest
  4.     .RowSourceType = "Table/Query"
  5.     .RowSource = "SELECT Plant_abbr FROM Plants"
  6. End With

Now the above query just displays the Plant_abbr column. If you wanted to be able to switch the row source based on some identifier in the main form, you can do that using an if else endif construct (see below) or a select case construct as I showed you in my previous post.

Expand|Select|Wrap|Line Numbers
  1. Dim cmbTest As ComboBox
  2. Set cmbTest = Me!cboSelectPlant
  3. With cmbTest
  4.     .RowSourceType = "Table/Query"
  5.      If Parent.[txtbox1].Value =  xxx then
  6.                 .RowSource = "SELECT Plant_abbr FROM Plants"
  7.      Elseif Parent.[txtbox1].Value =  xxx then
  8.                 .RowSource =  "Select XXXXXXXXXXXXXXXX "
  9.      Else
  10.                 .RowSource =  "Select XXXXXXXXXXXXXXXX "
  11.      End If
  12. End With




.
Jul 13 '08 #10
I have found out from some other people that what I'm trying to do is impossible, because I'm trying to set the properties of a query result in datasheet view. There are only a few things that can be changed I'm told. Can't add comboboxes and change backcolors with it.
So I have started again but this time I have made a form with a query that opens all the columns of the table as rowsource. Then I hide the columns I do not wish to view. Locking works, changing backcolor works, but now I only need to find out how to set column order and how to order by certain columns. I'm currently wrestling with the "ColumnOrder" property to get the columns in the proper order. I still have some things I need to try, if I get stuck somewhere you might see another post from me hehe

Thanks alot for all your help so far, I appreciate it.
Jul 15 '08 #11
puppydogbuddy
1,923 Expert 1GB
I have found out from some other people that what I'm trying to do is impossible, because I'm trying to set the properties of a query result in datasheet view. There are only a few things that can be changed I'm told. Can't add comboboxes and change backcolors with it.
So I have started again but this time I have made a form with a query that opens all the columns of the table as rowsource. Then I hide the columns I do not wish to view. Locking works, changing backcolor works, but now I only need to find out how to set column order and how to order by certain columns. I'm currently wrestling with the "ColumnOrder" property to get the columns in the proper order. I still have some things I need to try, if I get stuck somewhere you might see another post from me hehe

Thanks alot for all your help so far, I appreciate it.
You are welcome. I can't confirm about dataSheet view, but the code I gave you works in form view because I use it all the time. As far as ordering the columns in your query, you can use an "order by" clause in sql view or go to the query grid and place the columns in the order you want them and then select the type of sort from the sort row.
Jul 15 '08 #12

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

Similar topics

1
by: A.J.M. van Rijthoven | last post by:
I have a table instrumenten (INSID Instrumentname, CATID), a table Categorie (CATID, Categorydescription), Netten (NETID, description of net) and a table (kpltblinstrument) that links the...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
2
by: AA Arens | last post by:
Somebody willing to assist me in the following? I want to have values from one field copied to another field when I choose choose a item from a drop down menu. I have 2 forms: 1 Company...
10
by: Thelma Lubkin | last post by:
My form/subform combination that allows user to display 'ColorSet' records, move to other records via a selector, to add,delete, and edit them, and to manage the related 'Color' records from the...
1
by: gsb58 | last post by:
Hi! In a typical frmOrders with a subform: frmOrderdetails you would surely like the Items field to be a combobox in order to lookup values. Anybody that know about an article on this...
1
by: Mariel | last post by:
Hello, I hava a main form F1, form with a subform F2 in datasheet view. There is a combobox in the main form C1, and a combobox C2 in the subform. I want the dropdown options of the combobox...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
6
by: naschol | last post by:
I am somewhat of a novice and am trying to do a somewhat complicated thing (to me, anyway). What I would like to do is populate the field Entry Fee in the subform (Category Entries table) from a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.