What do I need? I think you need to code in after update, but what?
Combox has 4 selections under control named [Section]
[Section]
A
B
C
D
Listbox After Update:
Like [Forms]![Myform].[Section] & "*" doesn't work
Thanks
What do I need? I think you need to code in after update, but what?
Combox has 4 selections under control named [Section]
[Section]
A
B
C
D
Listbox After Update:
Like [Forms]![Myform].[Section] & "*" doesn't work
Thanks
What do you want to do? Do you want the listbox RowSource dependent on selection in combobox, something like:
SELECT field1 FROM table WHERE field2 = [combobox];
Then code in the combobox AfterUpdate event or the listbox GotFocus event would be:
Me.listboxname.Requery
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
June7,
Corrrect, I want the list box output to be dependent on the combobox selection
Combobox=[Section]
Combobox row source = SELECT Distinct Reports.Section FROM Reports ORDER BY Reports.Section;
Listbox=[Report Name]
Listbox Row Source = SELECT Reports.[Report Name] FROM Reports WHERE (((Reports.[Section])=[Section]));
If I put: "Me.[Report Name].Requery" in the Combobox AfterUpdate or Listbox GotFocus, I get a MS Access can't find theObject Me. I tried it in VBA and get Runtime Error 2465.
Recommend no spaces or special characters/punctuation (underscore is exception) in naming convention. Should not use reserved words as names. Reports and Section are both reserved words. https://support.microsoft.com/en-us/kb/286335
If you do those things, then enclose names in [], although even that will not prevent some issues
What do you mean by 'in the Combobox AfterUpdate or Listbox GotFocus' - do you mean in the event property? Doesn't go there. Select [Event Procedure] the click the ellipsis (...) to open VBA editor. Type code in procedure.
Post the complete procedure code.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Combobox=[Area]
Combobox row source = SELECT DISTINCT Document.Area FROM Document WHERE (((Document.Area) Is Not Null)) ORDER BY Document.Area;
Listbox=[Report Name]
Listbox Row Source = SELECT Document.[Report_Name] FROM Document WHERE (((Document.Area)=[Area])) ORDER BY Document.[Report_Name];
Combobox - After Update Event:
Private Sub Section_AfterUpdate()
Dim Area, Report_Name As String
[Me]![Report_Name].[Requery]
End Sub
You declare variables but don't set them with values. Why do you have those variables?
The combobox is named Section or Area? The code is for a control named Section.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Private Sub Area_AfterUpdate()
[Me]![Report_Name].[Requery]
End Sub
Try:
Me.[Report_Name].Requery
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Documents.accdb
This is what I have
The controls must be UNBOUND, otherwise you change the data in the record. And since the source of the lists is the only table in the db, you do not want to change the data by selection from these controls.
There is no reason to have the form RecordSource set.
The combobox is named Section so either change the combobox name or change Listbox RowSource. Access is being confused by the Area name. Change the combobox name to cbxArea and make other edits as appropriate.
Also, the listbox is named Reports but the code is for a control named Report_Name.
Set the appropriate event properties to [Event Procedure].
Private Sub cbxArea_AfterUpdate()
Me.Reports.Requery
End Sub
Private Sub Reports_GotFocus()
Me.Reports.Requery
End Sub
Last edited by June7; 09-24-2015 at 05:10 PM.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.