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

ComboBox or SubForm?

675 512MB
I have a form, bound to tblMain. I have tblSub, which is related to tblMain with a foreign key, all nice and proper database design.

I want to display the rows of tblSub in a control, but neither ComboBox nor SubForm seem to be easy to implement.

The primary purpose of this control is that when a row is clicked, then "strWork = strWork & xxx" where xxx is the correct field of the subform, or the correct column of the combobox.

I will also need to edit, delete, and add rows, both by the user, and with VBA.

ComboBox:
Use - when clicked, the .column contains the correct text
Update - Cannot know what to change, and will need another form to actually do any modification of the data. Note that this is not a "Not in List" issue as it may be an edit of a row that already exists, therefore not-in-list fires, but new row should not be added.

SubForm:
Use - there is no nice event for a row being clicked. OnCurrent fires for other reasons also, so the concatination creates errors. Will require OnClick for every field.
Update - easy, as all updatable fields can be displayed, unlocked, and enabled.

How should this problem be resolved?
Apr 2 '09 #1
17 3258
NeoPa
32,556 Expert Mod 16PB
I don't have a full solution for you OB, but with a subform, could you not add an unbound control (CheckBox, CommandButton, etc) that triggers the code instead of OnCurrent. Typically, just by clicking on the control, the desired record will be selected in the subform. Just an idea.
Apr 3 '09 #2
OldBirdman
675 512MB
Yes, of course I can do that. It is just that it takes space.

I have needed this solution in several databases, and others might also. I am fishing for ideas. Thank you for yours.
Apr 3 '09 #3
NeoPa
32,556 Expert Mod 16PB
I hear you OB.

I'm not aware of a more built-in alternative. Let's see what some of the other experts can come up with.
Apr 3 '09 #4
DonRayner
489 Expert 256MB
Hey OB,

If you use a subform in data-sheet view you can use the forms click event to fire your code. When a user clicks on the record-selector the event will fire.
Apr 4 '09 #5
OldBirdman
675 512MB
Thanks for another suggestion. Yes, either continuous forms or datasheet view will (optionally) have record selectors. The click event fires if the record selector is clicked. It does not fire if any field is clicked.

A combobox or listbox will fire a click if any column is clicked, not just the left side.

A subform is easier to correct/update, because cboControl.column(2) = "xxx" produces an error, even though the control is bound. Subforms are harder to work with during design, however.
Apr 4 '09 #6
OldBirdman
675 512MB
I've decided that I need to go with a sub-form. I will have a click event on each textbox, and no record selectors, as space is a consideration. The subform will make it easier to add, delete, and update the records.

I used the wizard (access 2000) to create the subform control. I cannot display my records in the correct order.

1) Can I specify a sort order in design view? If yes, how?

2) From VBA, how do I change the sort order of a subform from code in the main form? From code in the subform?

Main form name = fMain; Sub-form name sfDetails
Apr 6 '09 #7
NeoPa
32,556 Expert Mod 16PB
@OldBirdman
The order records are shown in a form depends on the RecordSource. A query can have the ORDER BY clause set which will give you your required sorting.
Apr 6 '09 #8
NeoPa
32,556 Expert Mod 16PB
@OldBirdman
If you're talking about changing the sort order after the form has already been displayed, then each form has an OrderBy property. See Referring to Items on a Sub-Form for how to reference that from your main form. I don't know if a .Requery of the subform is required after changing the property.
Apr 6 '09 #9
OldBirdman
675 512MB
I've avoided using subforms because I can't make any changes without closing everything, doing my editing, and then restarting the program, but that is probably another thread.

So I'm really a beginner here. My subform (on the main form) has properties SourceObject and LinkChildFields which appear to be the determining factors as to what is displayed. I don't think these are what you refer to.

Within the subform itself, there is an OrderBy property. That seems to do nothing. Why not? So the only way is to work with the RecordSource property directly? This would therefore be true in both design view and VBA.
Apr 6 '09 #10
FishVal
2,653 Expert 2GB
Seems like your subform SourceObject is table/query. Isn't it?
Apr 6 '09 #11
OldBirdman
675 512MB
It was a Table, with only the table name in Record Source. That is the way the Wizard set me up. Seemed like the subform Order By property should allow me to display these records in my preferred order. Couldn't make that work.

Record Source is now a query "SELECT ... FROM ... ORDER BY Type, Location". That does work, and "If it ain't broke, don't fix it!" applies now. I will go that way.

But it does seem like if I wanted command buttons over each column, I should only have to change the Order By property and not have to run a query against the original table each time. Sort the 10 displayed records rather than SELECT from 50,000 records and then sort.
Apr 6 '09 #12
NeoPa
32,556 Expert Mod 16PB
I believe the ordering is not applied unless you set OrderByOn to True in your code :
Expand|Select|Wrap|Line Numbers
  1. {Form}.OrderBy = "{Field1},{Field2}"
  2. {Form}.OrderByOn = True
This property is not shown for forms in the Properties Window, so it's easy to miss.
Apr 7 '09 #13
OldBirdman
675 512MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Me.OrderBy = "Type DESC"
  3.     Me.OrderByOn = True
  4. End Sub
This code did not sort the records on the subform. As a matter of fact, the first time the subform was updated (i.e. when the first record was displayed on the main form), it showed zero records. Changing to the 2nd record then displayed all the records for the subform. But not sorted! returning to the first record displayed correctly.

Using VBA to set OrderByOn, and the property sheet to set OrderBy did not work either.

I always seem to have trouble using subforms. I guess this thread started when I tried to avoid using a subform. Referencing controls on a subform gives me a headache.
Apr 7 '09 #14
NeoPa
32,556 Expert Mod 16PB
I'm afraid I haven't got an example to play with. I got the info from the help system. If I get some spare time I may see if I can knock something up, for curiosity's sake, but I don't use them much either :(
Apr 7 '09 #15
OldBirdman
675 512MB
Don't take your time. I'm going to use a query, not a table, to bind the form. This seems to work OK. At least for now I get predictable results and for this application the table is only a couple of thousand records, so efficiency not an issue.

But, if a form is bound to a dynaset, is there a guarantee that the records of the form are in the same order as the dynaset? For now, seems true!
Apr 7 '09 #16
NeoPa
32,556 Expert Mod 16PB
I would have expected the answer to be "No". After all there is an OrderBy property for the form, but your experience seems to indicate otherwise :S

It doesn't add up for me, but maybe I'm missing something.
Apr 7 '09 #17
OldBirdman
675 512MB
If the dynaset is not sorted, or sorted in an order that is incorrect for the form, then it makes sense that the form have an OrderBy property to sort the dynaset. I would expect this to work without the need for VBA coding.

As the sort order is not guaranteed in a Select Query, why would we assume that a form's dynaset have a predefined order. Viewing the table in datasheet view from the tables tab of the database window does not display the stored order.

Assume I create a table, and load it by typing rows in datasheet view. Assume the autonumber key field is random, not sequential. The keys are now out of order, although if I close & reopen the datasheet view, the rows will appear ordered. I believe that here the order is the order entered.

Assume I compact/repair this database. What is the order of this table now? All I can assume is that it is not in the order I want for my form.

I need my data in my order, and for now I will bind my data to my form by using a Select query as a Record Source.
Apr 8 '09 #18

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

Similar topics

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...
1
by: New2Access | last post by:
I posted this yesterday but perhaps I wasn't clear enough. I have a table called History with 4 fields "Week" "Employee" "Project" and "Hours" Each of those fields (except Hours) are based on...
2
by: Tom | last post by:
I have the following tables: TblState StateID State TblCounty CountyID StateID County
1
by: bcreighton | last post by:
I have created a bound subform on an unbound masterform linked together with a common field (A store's identification number) using an unbound combobox on the masterform and an invisible field on...
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...
5
by: ApexData | last post by:
I have a ComboBox, when dblClicked, displays the combobox's row content in a continuous subform. Changes can be made to this content in the subform and then closed. The ComboBox needs to be...
3
by: ApexData | last post by:
COMBOBOX REFRESH DILEMMA ' I have been working for hours trying to figure out how to requery a combobox in a subform, from a Popup form ' that this subform had launched. Basically, I designed...
13
by: BASSPU03 | last post by:
Hello, folks. This is my first post and I only began to work extensively with Access about 3 weeks ago. I'm running Access 2003 on Windows XP. I'd like a textbox in subform2 to reflect the value...
1
by: Rosie | last post by:
I have a main form with header info w/ 'tHeader' as the control source. I have a subform with 'tDetail' as a control source. They're strung together by a field named MA_ID. This works...
1
by: sirdevo | last post by:
There is one combobox on a subform named Report Soil Series Subform1. The combobox is named cboSoilSeries. I need to disable this so the user can't enter values. I could also disable the whole...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.