Access: Dropdown doesn't display value in first record of continuous subform - ms-access

I have a continuous subform in an Access 2003 form. The first control on the subform is an unbound dropdown box. When the form (and subform) are opened the dropdown on the first record receives focus, but the text is blank (just a blinking cursor). If I click on any other record, the first record's dropdown text then display the correct value (and the record I clicked on does not go blank).
I tried the following line
Call DoCmd.GoToRecord(acDataForm, "DetailsSubform", acNewRec)
in the both the main form's and subform's Load, Open and Activate events with no luck. Either I get an error that the subform isn't open, or there's a conflict with the routine that populates the dropdown.
I'm looking for a way for either the dropdown to display its value, or simply jump to a new record (my client would prefer the latter but can live with the former). More information can be provided if needed, I just wanted to start with an overview. Thanks.

You probably need the current event. Note that an unbound control in a continuous subform will display the same value for all records.

Related

MS Access 2016: When TabControl tab regains focus, requery listbox

I have a Tab Control element containing 2 tabs: Tab1 and Tab2. Tab2 contains a ListBox element whose RowSource queries the data that gets submitted in Tab1.
Say the user opens this form containing these 2 tabs. They are originally on Tab1. in the Form_Load event for Tab2, it queries the data it needs to populate its ListBox. Now they switch tabs to Tab1. They enter some data and submit a new record to the corresponding table (the same table that the Tab2 ListBox uses as its RowSource). When the user switches back to Tab2, they don't see this newly added record.
What I have done so far is that when the user clicks anywhere in the ListBox, it calls Requery, and then the record will show up. This isn't enough as it's not intuitive for the user to have to click on the listbox to update its contents.
I have tried putting this Requery code in a Form_Load, Form_Activate, GotFocus, but nothing works. I know you can detect the TabControl clicks, but how can I access the forms and the elements that they contain?
Any ideas on how to requery this listbox whenever the tab gains control?
If you want to add code for a specific tab on a tabcontrol, the most convenient way to do that is to write code in the TabCtl_Change event. That occurs when the tab control is changed. E.g.:
Private Sub MyTabCtl_Change()
If MyTabCtl.Pages(MyTabCtl.Value).Name = "Tab2" Then 'The tab control just changed to your page
'Requery that list box
End If
End Sub
Note that, if you're not using a tab control at all, but a navigation control (which it does sound like, tab controls don't necessarily have subforms on them, and don't have Form_Load events, forms do)
You're most likely looking for the On Activate trigger.
Then, in the code just use Form.Requery or Form.Recalc depending on which you're actually looking to do.
Alternatively, you could use the same control the user is using to submit records to trigger a requery. Although, that would require a specific Form to be called into focus.

Unexpected Tab key behavior in Datasheet form subdatasheet

When I tab through records in my (datasheet) form, the tab key behavior is as expected; Focus moves to the next field, and then at the end of the fields moves to the next record. In forms where I have master-child subdatasheets, when the subdatasheet isn't expanded and the user tabs past the end of a record, focus moves to the next record. This is good / what I want. When a subdatasheet is expanded and the user tabs past the end of the master record, focus moves to the first field in the child subdatasheet. Again this is good / what I want.
What happens on the next tab key press is my issue. Rather than moving focus to the next field in the subdatasheet, focus goes straight to the next record in the master datasheet. I expect and want focus to go to the next field in the subdatasheet.
I have been playing with the tabstops and cycle properties on both the main form, subform, and subform control within the main form, and cannot come to a configuration where I get the behavior I desire.
Solved this now and thought I should log it here. Was a pretty stupid problem caused by an oversight on my part.
Basically, all of the controls on my subdatasheet were being set to locked and tabstop = false, in a procedure I have to apply control settings by control name. So I'd actually made those settings a while ago, forgotten, and then assumed that the user should be able to tab through them.
Obviously Access was hitting the subdatasheet control, going "no controls available to tab through here", and so immediately exiting the subdatasheet control.
When I was trying in code to set focus to any of the controls, the reserved error 2950 must've been because the controls weren't tab-stoppable.

Requery of subform does not activate conditional formatting and puts new record at the bottom

I have a form with a 2-page tab control.
The first page has a subform with a button on the subform that's supposed to requery another subform that is on the second page.
Forms!myMainForm!mySubForm.Requery
The main form and its fields are used to create new records and the subform on the second page shows these records.
Here's a screenshot of page 1's subform and button:
http://i.imgur.com/RLsgcSi.jpg
When the button is clicked, the subform on the second page shows any new record at the bottom of the list instead of being sorted in descending date/time order. Also the Funding Rate field does not seem to get its conditional formatting applied:
http://i.imgur.com/QRvI5fy.jpg
I've been able to get the subform to display correctly if I also add some VBA to the button to switch to the second page of the tab, but I'd rather not do this.
Is it possible to requery a subform and have it display correctly when the user is ready to see it?
Migrate froms Tabs to Navigation Control. Usual Tabs are preloaded and will increase the main form load time. On the other hand, Navigation control only loads the form when its opened. This eliminates your needs to manually re-query the second tab.
PS: I'm interested in something in your form, what is your best contact method?
Forms!myMainForm!mySubForm.Requery
This requeries the mySubForm control on myMainForm, but not the subform itself.
Try instead:
Forms!myMainForm!mySubForm.Form.Requery
(note: I'm not 100% sure this will solve the issue)

Expression in control source and default value

I am pulling my hair here.
I want to link 2 subform fields to a field in the main form.
I used Parent.MyFieldName.Column(3) for the control source of the first subform field and it is displayed fine. The Row source of my second subform field is using the first subform field as a criteria for its query.
The problem is that this combobox remains empty when I use the above code but is populated if I give the first field a constant value.
Feels like the combobox is getting filled before the retrieval of data from the first subform field.
I tried moving the above code form control source to default value but then both fields remain empty.
What am I doing wrong?
I have found the main reason why things weren't working - Subform controls load before the rest of the main form. This means that at the time my subform dropdown menu seeks the data in the other form fields they still haven't appeared and thus I am left with an empty dropdown menu.
I solved this by removing the sourceobject of the subform control and adding
Me!Subform1.SourceObject = "SubformOtpuskaneIzhMat"
In some events in the main form.

Access 2007 Split form VBA: acNewRec on open prevents tabbing through form - acts like the first field is not 'selected'

I hope someone can help me out, or at least help figure out a workaround.
I'm using Access 2007's split form feature, and have the code below run on the Form_Open event, as well as after two button_click events. The code works fine when run after the button_click events, but when it runs on the form_open event, it causes problems.
If form is opened and user enters text in the first field, he/she cannot use Tab or mouse to select the next form field. The user is stuck on the first form field until pressing Esc to cancel the data entry. In order to successfully enter data in the first form field when the form is opened, a user must first select another form field, then re-select the first form field then enter text in first form field. After this nonsense, the user CAN select next form field with Tab or mouse. This must be performed once every time the form is launched. The same VBA code on the button_click events works fine.
Noteworthy: When the form is first opened, NONE of the form fields in the datasheet section of the form appear 'Selected'. When a user begins to enter data in the first form field, the 'new record' marker (*) moves to the second row as it should, but the first row does not show the data being input. This behavior is odd.
After performing the clear field, click another field, click back to first field workaround described above, the datasheet shows properly selected fields and Data as it is input.
Any ideas? Is this a bug? Is there an easy workaround, such as performing the field-select workaround via VBA at form open?
Any help is MUCH appreciated.
Code:
DoCmd.ApplyFilter , "([Contractor].[CheckOutStamp] Is Null)"
DoCmd.GoToRecord , "", acNewRec
Link to mdb:
https://docs.google.com/leaf?id=0B-jx09cwIQDsYWM2MzMzMDQtYjUzNi00N2E5LWFjYTktNzFiYWYzMDZiYWU1&hl=en&authkey=CPPmoMEF
Some thoughts:
Try moving it from OnOpen to OnLoad. The events in OnOpen can happen before the data is actually loaded, where as OnLoad happens after that is already done.
Also, you might want to just set the form's Filter property to [Contractor].[CheckOutStamp] Is Null and set the FilterOn to Yes, and set the form to DataEntry, which means it defaults to a new record upon open, and doesn't load any of the older records. Once it's open, you can change the form's edit/add mode to whatever you like.