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

Get data in one subform to load before onCurrent event of other subform

I have a main form called f_MainTripForm_Admin with a split view. The main form has fields relating to a trip.

The main form has 2 sub forms. The subforms have fields related to activities that occured on a trip, eg meetings. One trip can have many meetings assoicated with it:
SubForm 1 - f_ActivityDetails_SFC: Form with tab control view of activity-related fields for one Activity
SubForm 2 - f_ActivityDetails_Datasheet: datasheet view showing a list of all Activities for that trip.
The OnCurrent event for the ActivityDetails_Datasheet calls the following code:

Expand|Select|Wrap|Line Numbers
  1. Sub FilterActivities()
  2.  
  3. Debug.Print "Start FilterActivities()"
  4. Debug.Print " Set up filter - Display record in form that corresponds to record in datasheet"
  5.  
  6. Dim sFilter As String
  7. If Not Forms!f_MainTripForm_Admin.NewRecord Then
  8. sFilter = "Activity_ID = " & Forms![f_MainTripForm_Admin]![f_ActivityDetails_SFC].Form![Activity_ID]
  9.  
  10. Debug.Print " Display Activity_ID: "; Forms![f_MainTripForm_Admin]![f_ActivityDetails_SFC].Form![Activity_ID]
  11. Debug.Print "Display Filter: "; sFilter
  12.  
  13. Forms!f_MainTripForm_Admin!f_ActivityDetails_SFC.Form.Filter = sFilter
  14. Forms!f_MainTripForm_Admin!f_ActivityDetails_SFC.Form.FilterOn = True
  15.  
  16. End If
  17.  
  18. Call TabView
  19. Debug.Print "End Start FilterActivities()"
  20.  
  21. End Sub
When the f_MainTripForm_Admin is first opened, everything loads properly.

However, when I select a different record in f_MainTripForm_Admin's split form, the data in the f_ActivityDetails_SFC form does not load, (the Activity_ID field shows (New) ) so the sFilter can not get a value for the Activity_ID called for in line 8 of the code above. I get the error:

Run-time error '3075'
Syntax error (missing operator) in query expression 'Activity_ID = "



All the related Activities are displayed in f_ActivityDetails_Datasheet.

How can I get the data in the ActivityDetails_Admin to load before the OnCurrent event kicks in for f_ActivityDetails_Datasheet?

Many thanks,
Sandra
Sep 28 '12 #1
4 2475
zmbd
5,501 Expert Mod 4TB
If I am reading your code correctly:
(it's late and I'm on a friend's laptop :) )O

Line 8 is calling for information from the subform that is then fed back into the same subform on line 13; however, the mainform has changed from one record to the next so the subform has no reference to the new records related between itself and the main form - hence, no information to pass.
Sep 29 '12 #2
Hello Z -

I reworked the code (below) and the Activity records are now loading correctly.

The issue I have now is that the recordset in f_ActivityDetails_Datasheet does not update when I edit, delete or add an Activity in ActivityDetails_Admin.

f_ActivityDetails_Datasheet has the following properties:
DataEntry = No
Allow Additions, Deletions, Edits and Filters = Yes

I dont need to be able to update any data in f_ActivityDetails_Datasheet - I just need it to reflect the changes made in ActivityDetails_Admin when I select a different record in ActivityDetails_Datasheet.

I think this might have to do with the definition of the recordset is fixed somehow and I need to clear it.

Is

Expand|Select|Wrap|Line Numbers
  1. Set rs = Nothing
the correct approach?

Thanks!
Sandra


Expand|Select|Wrap|Line Numbers
  1. Sub FilterActivities()
  2.  
  3. Debug.Print "Start FilterActivities()"
  4.  
  5. Debug.Print "     Set up filter - Display record in f_ActivityDetails_Admin that corresponds to record in f_ActivityDetails_datasheet"
  6. Dim sFilter As String
  7. Dim rs  As DAO.recordset
  8. Dim lRecordCount    As Long
  9.  
  10. DoCmd.Echo False
  11.  
  12. 'Define the record set for the Activities associated with this Trip
  13.  
  14. Set rs = Forms!f_MainTripForm_Admin.ActivityDetailsDatasheet.Form.RecordsetClone
  15.  
  16.   lRecordCount = rs.RecordCount
  17.  
  18.     If Not Forms!f_MainTripForm_Admin.NewRecord And lRecordCount <> 0 Then
  19.     Debug.Print "We have found Activities assoicated with this Trip"
  20.     Debug.Print "ActivityDetailsDatasheet has: " & lRecordCount & " records(s)"
  21.  
  22. 'Show me the current Activity_ID
  23.  
  24.     Debug.Print "  datasheet Activity_ID is: "; Forms![f_MainTripForm_Admin]![ActivityDetailsDatasheet].Form![Activity_ID]
  25.         sFilter = "Activity_ID = " & Forms![f_MainTripForm_Admin]![ActivityDetailsDatasheet].Form![Activity_ID]
  26.  
  27. 'Show me the current Filter
  28.         Debug.Print "  Current Filter is: "; sFilter
  29.         Forms!f_MainTripForm_Admin!f_ActivityDetails_SFC.Form.Filter = sFilter
  30.         Forms!f_MainTripForm_Admin!f_ActivityDetails_SFC.Form.FilterOn = True
  31.  
  32.   Else
  33.     'If there are  NO Activities assoicated with this Trip
  34.     'show 0 records in the recordset
  35.     Debug.Print "ActivityDetailsDatasheet has no records: " & lRecordCount & " records(s)"
  36.  
  37.   End If
  38.  
  39. Set rs = Nothing
  40.  
  41. Debug.Print "Call TabView"
  42. Call TabView
  43.  
  44. Debug.Print "End FilterActivities()"
  45.  
  46. DoCmd.Echo True
  47. End Sub
Oct 2 '12 #3
zmbd
5,501 Expert Mod 4TB
Yea, For getting things working!

Respectfully:
Sandra, with the change in the scope of the question, the forum guidlines ask that the new question be started in a new thread (one question per thread).

Before we work in the new question, please repost.
I don't want to split your current post out of this thread as it contains the re-worked code that is working for you.
Oct 2 '12 #4
Thanks Z -

Reposted here.
Oct 3 '12 #5

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

Similar topics

0
by: Ellen Manning | last post by:
I've got an A2K form with a subform based on a query. This query has a checkbox and an amount field and returns records if checkbox is checked. I Dsum the amount field and display on the main...
0
by: Colin | last post by:
In access 2000 I need to filter records in a Subform by pushing a button on a command button located on the Main form. The Main form is blank. Its only purpose is to contain the subform which is...
1
by: New2Access | last post by:
Hi, I have a form thats used to enter records into a table. The table and form have fields for Name, week, project, and hours. To assist users, I wish to add a subform that will show them how...
18
by: Darryl Kerkeslager | last post by:
I don't do much with subforms - in fact I've deliberately avoided them - but .... I have a tab control that will contain several subforms, each bound to a separate table, and each table/subform...
1
by: NBruch | last post by:
Ok let me explain what im trying to do: i need a combo box which needs to be linked to a listbox (or combo box doesnt matter which really) then the listbox should bring up the record in a...
1
by: luv4nrt | last post by:
Hello all, I have a membership dB in which I have a form that updates data in 4 tables. One of the tables is bounded to a subform within the Main membership form. I am trying to link all four...
3
by: virtualgreek | last post by:
Dear all, I have a scenario that is driving me nuts. (MS Access 2003) I have a form/subform (Continuous form) where it gets its data from tables Order and Order_Details. In the footer...
1
by: Elainie | last post by:
I have a main form and in it I have a datasheet subform filtered on surname, I would like the users to select a name in their list on the subform then the data moves up into the main form... Is...
2
by: post | last post by:
Sorry that this is rather basic. But I have tried the various suggestions given in this group and cannot get them to work. I have a main form, for simplicity called "Main". On it are two...
4
by: Savita23 | last post by:
Hi, I have a subform in datasheet layout embedded in the main form.I want to invoke a procedure on the double click of each record in the subform.Is there a away by which I can fire the double...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.