I am working on an MS Access Form. I am trying to have a Combo Box on the form who's list is narrowed based on information earlier in the form. I have a Query saved in the database that gets the list properly.
The problem I am having is that the query is not called after each update of the form so the Combo Box's list is always what it was when the form was opened.
I have tried to force an update using Me.MyComboBox.Requery in the AfterUpdate event of the previous control but this only requeries the record source of theform, not the row source of the Combo Box.
I have also tried changing the row source property to force a requery but that did not work eithier:
Private Sub PreviusControl_AfterUpdate()
Me.MyComboBox.RowSourceType = "Table/Query"
Me.MyComboBox.RowSource = "qryDynamicComboSource"
End Sub
Thanks in advance!
It looks like everything you're doing is correct. Check your query design if it's actually changing based on your parameters.
Related
I have created on a database a Dlookup function to change the email address of a manager whenever the managers area is selected. It works fine but now that the control source is the Dlookup it doesn't save the results any more in the personal table.
I read up on http://p2p.wrox.com/access-vba/77907-how-save-results-dlookup-function.html a method to have a separate hidden box which displays the results from the table, which works but my trouble is now connecting the Dlookup result to the other text box.
I obviously cant control source the Dlookup result so I've instead tried to make it an before update event using the following code;
Option Compare Database
Private Sub ASMail_AfterUpdate()
ASMEmail.Value = ASMail.Value
End Sub
However this has not taken effect at all. The textbox does not change whenever I adjust the Dlookup results, and I've tried the same code in the other Change event which didn't work either.
You don't need a separate hidden textbox.
Leave the textbox control source of the manager's email linked to the personal table field and simply update the textbox value to the DLookup value when the manager area is selected.
I don't know how the manager area is selected, but as a combobox example, it would be like this:
Private Sub Combo_AfterUpdate()
Me.ASMEmail.Value = Nz(DLookup("Value", "Domain", "Criteria"), vbNullString)
End Sub
MS Access 2007, Win 7 32-bits
Is there a way where I can access an open query in datasheet view in access to get the current field value and current field name?
I won't put it into a form since it is a crosstab query and i'd have to generate and get rid of controls dynamically but i'm not fond of messing with forms controls that way with VBA. I know i can put a dynamic column report and bind an event on the controls but I'm asking if there are events or objects that can let me access directly the query.
Perhaps a recordset clone? But I haven't find anything on google.
Of course this is in VBA
Best regards,
It may be possible to work around your requirements. The crosstab is contained by a subform:
Source Object : Query.xtab
The Control Source for the two textboxes is:
Ctrl : =[screen].[activecontrol].[name]
Content: =[screen].[activecontrol]
Which means they show which ever column ans column contents the user selects in the crosstab subform. However, they will also show any other selected control on the form. ClickMe does not change the selected control, so the selected items remain the same in the textboxes.
You can also enter MacDermott's code for getting the current control's index, so the current control selected on the xtab query subform is displayed dynamically
Public Function ControlIndex(ctl as Control) as long
Dim i as Integer
For i=0 to Me.Controls.Count-1
if me.Controls(i) is ctl then
ControlIndex=i
exit for
end if
next
End Function
And finally this can help when changing from one control to another in the same record to keep the textboxes current.
So in MS Access 2010 I have a main form for viewing client details, and tabbed subform navigation with subforms showing information in different tables for said client. On one page, i have a combobox to select a date for viewing a testing session related to the client. I am trying to get the first combobox value to be selected automatically when the user goes to this tab and/or cycles through other users while viewing this tab. My simple VB code is below:
Private Sub Form_Current()
Me.DateOfScreening.Requery
Me.DateOfScreening.Selected(2) = True
End Sub
The requery command is executing (paging through different clients will update the combobox values, and commenting that line out stops that behavior, so I know this code block is getting executed), but the Selected command appears to not select anything.
I hope I am just missing something obvious
For some reason, setting the selected row index for a combo box has not behaved well for me.
Could you just set the combobox value directly, as in
Me.DateOfScreening = "yourValue"
Also, when referencing the control, you can use either
me.dateofScreening.column(0) 'if 0 is your bound col index
or maybe
me.dateofScreening.itemdata(0)
Also, could you do a debug.print(me.dateofScreening.column(0)) or msgbox (me.dateofScreening.column(0)) and let me know if it says anything.
I have a combo box on an form where the values are populated based on the value in a separate field.
To do this, I have created a combo box and set the "Row Source" to run a SQL statement.
The problem I am having is that if the data in the field changes, the combo box values do not update.
How do I get access to re-run the query?
See whether this description is reasonably close to your situation.
My form has a text box, txtFoo, and a combo box, cboBar.
The row source property for cboBar is a query which references txtFoo. And I want the combo's contents updated in response to changes in txtFoo. The solution is to requery cboBar from txtFoo's after update event.
Private Sub txtFoo_AfterUpdate()
Me.cboBar.Requery
End Sub
I have had issues in the past with Requery not working or even hanging.
It's not pretty but you might want to try this:
Me.cboBar.RowSource = ""
Me.cboDemoUnit.RowSource = "your SQL statement"
Here is an example of what I have done recently to do the same exact thing, this should help! Its in an afterupdate sub.Example of dynamic combobox
Preface: I have a form which has tabs. In one of the tabs, I have a list box, a button, and a sub-form. The list box is populated from two tables and has a bound column.
Needed: I need the sub-form to edit existing records of one of the tables the list box is built on and append records to the same table on button click. The sub form is to be linked to the non-bound column of the list box. Please help.. I have tried a few things in Vb but could not complete..
--Chegu.
I am not sure if I understand you correctly, but if you want to select a line in the listbox, edit the respective record in the underlying table and then save the record and update the listbox, you could work along those lines:
The listbox should not be linked, neither should the subform.
Create a procedure
Sub UpdateSubform()
subform![id]=listbox!changetableID]
End sub
In the OnLoad event of the form and in the OnChange event of the listbox call this procedure
In the afterUpdate event of the subform:
Private Sub Form_AfterUpdate()
me.parent.requery
End Sub
I didn't check this out myself, because I am away from my access - but it should work along those lines.
If thats not what you are looking for, please edit your post and at least post the information whats in the listbox and where your subform should link to.