473,406 Members | 2,352 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,406 software developers and data experts.

Form/Subform interaction

I'm building a db for tracking support issues.

The form has two lists which I want to update based on selections elsewhere in the form, and I want to open selected records in the form when selections in the lists are double clicked.

The details:
ID - Autonumber field used as support ID
cboUID - User ID
cboAssetID - Asset ID

listAssetSupportHistory
listUserSupportHistory

The lists have the following SQL code to pull their contents (this is for listAssetSupportHistory, listUserSupportHistory pulls the field tblSupport.AssetID and uses tblSupport.UID as the selection criteria):

Expand|Select|Wrap|Line Numbers
  1. SELECT tblSupport.ID, tblSupport.UID, tblSupport.Date, Left([tblSupport.Problem],50) AS Problem
  2. FROM tblSupport
  3. WHERE (((tblSupport.AssetID)=Forms!formSupport!cboAssetID))
  4. ORDER BY tblSupport.ID;
  5.  
Problem is a memo field in tblSupport and so I'm converting to a text field for use in the lists.

The VBA code for the form:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboUID_Change()
  2. 'requery User Support History list
  3. On Error GoTo Err_Update_Click
  4.  
  5.     Me![listUserSupportHistory].Requery
  6.  
  7. Exit_Update_Click:
  8.     Exit Sub
  9.  
  10. Err_Update_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Update_Click
  13. End Sub
  14.  
  15. Private Sub cboAsset_Change()
  16. 'requery Asset Support History list
  17. On Error GoTo Err_Update_Click
  18.  
  19.     Me![listAssetSupportHistory].Requery
  20.  
  21. Exit_Update_Click:
  22.     Exit Sub
  23.  
  24. Err_Update_Click:
  25.     MsgBox Err.Description
  26.     Resume Exit_Update_Click
  27.  
  28. End Sub
  29.  
  30. Private Sub ID_AfterUpdate()
  31. On Error GoTo Err_Update_Click
  32.  
  33.     Me![listUserSupportHistory].Requery
  34.     Me![listAssetSupportHistory].Requery
  35.  
  36. Exit_Update_Click:
  37.     Exit Sub
  38.  
  39. Err_Update_Click:
  40.     MsgBox Err.Description
  41.     Resume Exit_Update_Click
  42. End Sub
  43.  
  44. Private Sub listUserSupportHistory_AfterUpdate()
  45.     ' Find the record that matches the control.
  46.     Dim rs As Object
  47.  
  48.     Set rs = Me.Recordset.Clone
  49.     rs.FindFirst "[ID] = " & Me!listUserSupportHistory
  50.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  51. End Sub
  52.  
  53. Private Sub listAssetSupportHistory_AfterUpdate()
  54.     'Set SoughtString with
  55.     Dim rs As Object
  56.  
  57.     Set rs = Me.Recordset.Clone
  58.     rs.FindFirst "[ID] = " & Me!listAssetSupportHistory
  59.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  60. End Sub
  61.  
The goal:
As I'm scrolling through the records in the form, I want the two lists to update with all the records from tblSupport that correspond to cboUID or cboAssetID.

Also, when creating a new record, selecting the affected user and/or asset will show the support history for each.

Neither UID nor AssetID are required in the database as there are issues that correspond to users and not to assets and vice versa.

Making selections in cboUID and cboAssetID do update the lists appropriately, but navigating through the records does not.

I assume this means Private Sub ID_Change() isn't the correct trigger. This isn't a complete necessity as in operation the form will most frequently open with a new blank entry and most searching of the records will be based on the selections I've made while creating a new entry. But I want to know how to make it work this way to make it as user friendly as possible as well as to further my own knowledge of VBA.

Also, because I don't want to leave the initial support record accidentally, I'd like to set the trigger (criteria) for opening the record selected in either list to a doubleclick and/or enter key press.

I'd been trying to use DoubleClick as the event action trigger, but that had not been working until I changed it to Private Sub listAssetSupportHistory_AfterUpdate().

Is there a way to set it to the DoubleClick and Enter events to trigger the record search?
Jun 29 '10 #1

✓ answered by NeoPa

I suspect you're looking for the Form_OnCurrent() event procedure. Let us know if this helps :)

Welcome to Bytes!

6 1907
NeoPa
32,556 Expert Mod 16PB
I suspect you're looking for the Form_OnCurrent() event procedure. Let us know if this helps :)

Welcome to Bytes!
Jun 30 '10 #2
So using the OnCurrent for a form event in place of the AfterUpdate on the ID:

Expand|Select|Wrap|Line Numbers
  1. Private Sub formSupport_OnCurrent()
  2.  
  3. On Error GoTo Err_Update_Click
  4.  
  5.     Me![listAssetSupportHistory].Requery
  6.     Me![listUserSupportHistory].Requery
  7.  
  8. Exit_Update_Click:
  9.     Exit Sub
  10.  
  11. Err_Update_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_Update_Click
  14.  
  15. End Sub
  16.  
This code doesn't work either.

The (faulty, apparently) logic I was using before was that anytime I navigated through the form, the ID field would necessarily change, and so tying the AfterUpdate event to the ID changing would thus trigger the necessary updates.

Should I tie the OnCurrent() event to something besides the entire form (formSupport)?

I've tested to make sure the requery syntax and system works by using the same action code attached to a button control.
Jun 30 '10 #3
Perhaps the best question is: What is the best resource you have found for listing and describing the various event triggers and what types of controls they can be used on?
Jun 30 '10 #4
NeoPa
32,556 Expert Mod 16PB
I use context-sensitive help.

Type Form in the Immediate Pane (or anywhere in your code would also work) then press F1. The Help window will open and prompt you to select Access Form (object) or just Access Form. Select the former and you will see a page open with loads of info about forms. Including a menu for Events.
Jun 30 '10 #5
Ok, I found how I was misunderstanding your instructions.

I was assuming by "Form" you meant the name of my form, as in "formSupport".

So, I modified my code to use the Form control action. It's working very well now thanks.
Jun 30 '10 #6
NeoPa
32,556 Expert Mod 16PB
LoL. I can see how that might be. I also didn't read your reply carefully enough, to be sure, or I might have picked it up. Never mind. Lessons learned so a good day :)
Jul 1 '10 #7

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

Similar topics

0
by: Josh C. | last post by:
Hello everyone. I'm a bit of an Access newbie, so please bear with me. Please go to http://www.dumoti.com/access/ to view the database - 536kb. I'll go straight into examples: In the form...
3
by: Simone | last post by:
Hi All, I have a Find Record button setup in most of my forms in order to find a specific customer's details. I have just noticed today though that this search will only find the customer if it...
5
by: ego | last post by:
Hi all , I had created the following Form/SubForm structure : MainForm SubForm A (SubForm of MainForm) SubForm B (SubForm of SubForm A) SubForm C (SubForm of SubForm B) SubForm D ...
9
by: PC Datasheet | last post by:
I'm stuck on something that seems should be easy and I need some help. My main form has an option group with five options. My subform chooses from different lists depending on which option is...
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...
3
by: ghat12 | last post by:
Hi, I have created a form containing 5 textfields/combo boxes and a command button to conduct searches for matching records. My results are currently displayed as a separate datasheet which is...
5
by: Ron | last post by:
Hi All, I've got a form called frmCust that has a subform on it called sfrmBalance. sfrmBalance's control source is a query called qryTrans4CustBal. sfrmBalance has one field on it called...
2
by: hawg1 | last post by:
I'm fairly new to Access and need help with form/subform. I've seen another access database in which a main form allowed the user to enter school class specific information shuch as start date,...
3
by: Steve | last post by:
Is there a way to put a main form/subform in a continuous form so I can scroll through all the records in the main form? Thanks!
1
by: troy_lee | last post by:
I have a table (Table A). It has one field, a PK. It is in a 1:M with another table (Table B). I am having trouble with a form/subform setup to view the 1:M records. On the parent form, there is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.