473,421 Members | 1,539 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,421 software developers and data experts.

If subroutine to get Now() value in date controls on parent form depending on an action on the subform

27 16bit
I have a from called CAD_CallDispSplitF. As the name implies, it is a split form. The form has a subform named CAD_Log_DispF. Link Master Field is ID
Link Child Field is ID_Activity
The link works fine.

The record source for the subform is

Expand|Select|Wrap|Line Numbers
  1. SELECT CADLogT.ID, CADLogT.EntryDateTime, CADLogT.Notes, CADLogT.ActionID, CADLogT.Dispo, CADLogT.ID_Activity, CADLogT.EmployeeID, CADLogT.TourID, TourT.UnitAvailable, ActivityT.DispDateTime, ActivityT.EndingDateTime, ActivityT.BeginDateTime
  2. FROM (CADLogT INNER JOIN TourT ON CADLogT.TourID = TourT.ID) LEFT JOIN ActivityT ON CADLogT.ID_Activity = ActivityT.ID;
  3.  
I have this BeforeUpdate event on the subform.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     Me.EmployeeID = DLookup("EmployeeID", "LocalUserT")
  4.  
  5.     If IsNull([EntryDateTime]) Then
  6.         [EntryDateTime] = Now()
  7.     End If
  8.  
  9.     Select Case ActionID.Value
  10.  
  11.         Case Is = 1: UnitAvailable = 0
  12.         Case Is = 2: UnitAvailable = 0
  13.         Case Is = 3: UnitAvailable = 0
  14.         Case Is = 4: UnitAvailable = 1
  15.         Case Is = 6: UnitAvailable = 1
  16.         Case Is = 7: UnitAvailable = 1
  17.         Case Is = 8: UnitAvailable = 1
  18.         Case Is = 10: UnitAvailable = 1
  19.         Case Is = 24: UnitAvailable = 1
  20.  
  21.     End Select
  22.  
  23.     If IsNull([DispDateTime]) Then
  24.         If ActionID = 1 Or 2 Then
  25.                 DispDateTime = Now()
  26.         End If
  27.     End If
  28.  
  29.     If IsNull([BeginDateTime]) Then
  30.         If ActionID = 3 Then
  31.                 BeginDateTime = Now()
  32.         End If
  33.     End If
  34.  
  35.     If IsNull([EndingDateTime]) Then
  36.         If ActionID = 6 Or 7 Or 8 Then
  37.                 EndingDateTime = Now()
  38.         End If
  39.     End If
  40.  
  41.  
  42.  
  43.  
  44.  End Sub
  45.  
Everything works fine up to the If syntax.

To spell it out in English, I will talk about only the first IF statement. What I want to happen is if the ActionID is 1 or 2 AND the DispDateTime field/control is empty, the the DispDateTime field/control should =Now(). If the DispDateTime field/control is not empty, then nothing should happen because I do not want it overwritten with a new date and time. If anyone can help me with the proper IF syntax, I can probably apply it to the other following IF statements. Thanks in advance..... Mark
Aug 24 '22 #1

✓ answered by NeoPa

Hi Mark.

I told you already what to expect if you try to update a record from within the Form_BeforeUpdate() event procedure. In fact I told you once then reminded you later.

Unless you're very careful with you logic you will get into an interminable loop as the very procedure you're running will be triggered again when you do an update.

However, at this stage you're just looking at the VBA syntax which is wrong on line #36 of your posted code. The appropriate syntax is :
Expand|Select|Wrap|Line Numbers
  1.         If ActionID = 6 _
  2.         Or ActionID = 7 _
  3.         Or ActionID = 8 Then

7 7854
NeoPa
32,556 Expert Mod 16PB
Hi Mark.

I told you already what to expect if you try to update a record from within the Form_BeforeUpdate() event procedure. In fact I told you once then reminded you later.

Unless you're very careful with you logic you will get into an interminable loop as the very procedure you're running will be triggered again when you do an update.

However, at this stage you're just looking at the VBA syntax which is wrong on line #36 of your posted code. The appropriate syntax is :
Expand|Select|Wrap|Line Numbers
  1.         If ActionID = 6 _
  2.         Or ActionID = 7 _
  3.         Or ActionID = 8 Then
Aug 25 '22 #2
MNewby
27 16bit
NeoPa, That corrected code worked. I know that you cautioned me about using the BeforeUpdate event, but when I put it in the AfterUpdate event, it locks up, and I must hit ESC to get it to release. When I have it in the BeforeUpdate, it works without a hitch.

So if I should not put it in the BeforeUpdate, where should I put it?

Mark
Aug 25 '22 #3
NeoPa
32,556 Expert Mod 16PB
Mark:
So if I should not put it in the BeforeUpdate, where should I put it?
To be fair Mark, if it's working OK in the Form_BeforeUpdate() Event procedure then it looks like your logic has avoided the problem.

Normally, and I actually did earlier, I'd suggest to use the Form_AfterUpdate() one instead, but if you have problems with that perhaps we can leave it where it is and look into those problems another time.
Aug 26 '22 #4
MNewby
27 16bit
Thank you NeoPa.... I just want to do things the right way and I'm trying to learn how. Again thanks... you're the greatest. Problem solved.
Aug 26 '22 #5
NeoPa
32,556 Expert Mod 16PB
Mark:
I just want to do things the right way and I'm trying to learn how.
That's music to my ears :-)

In short, if your Form_BeforeUpdate() routine updates the data in all circumstances then you have an interminable loop. The update triggers the Form_BeforeUpdate() routine. When it runs that triggers a further update. That triggers the Form_BeforeUpdate() routine again - which triggers another update, and on and on ad infinitum. Bear in mind the first requested update is never completed.

Access continues to follow the process until it exhausts all the resources available and crashes unceremoniously. Not pretty. Worth avoiding at all costs.

To be fair, if the logic is wrong you can get a similar loop even if you allow the update to complete before requesting a new one, but at least that doesn't crash Access and/or Windows. Make sure your logic doesn't depend on the update having completed if it's in the Form_BeforeUpdate() routine.
Aug 26 '22 #6
MNewby
27 16bit
Thank you for the explanation. Hopefully I can avoid that problem in the future. Have a great weekend....although I will be working on this LOL
Aug 26 '22 #7
NeoPa
32,556 Expert Mod 16PB
Hi Mark.

I'm around most of the weekend so feel free to drop a new question in if you need to. Not all such work is limited to working hours of course ;-)
Aug 27 '22 #8

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

Similar topics

3
by: steph | last post by:
Hi Group, This is about Access 2002. I've got a subform that is utilized in 2 other forms. That means: Form A displays subform S Form B displays subform S Now I wonder how can I know in S...
7
by: darnnnel | last post by:
I have a form and a subform. The subform is displayed as a datasheet. When a user selects a record on the list, I would like the parent for to show the contents of the record selected. Access 2007,...
1
by: nupuragr82 | last post by:
I have a parent form and on button click I am calling a child page where i have a textbox and a button. On button click of child form I am passing the value of the Textbox to the Textbox in parent...
6
by: solom190 | last post by:
Okay this is the situation I have two forms and they have a 1:M relationship. I don't have enough space screen-wise to do a traditional "drag form to form" to create a subform so what I did was...
27
by: tragaz | last post by:
Hi There, I'm a beginer in Access and VB. In my Database, I've got a form with a subform. the subform is a query from a table different than the table of the main form. those tables don't have a...
4
by: dgunner71 | last post by:
All, I have a Parent form where the Record Source is a query based on three tables (tblcustomers, tblEquipment, and tblWorkOrders). The Parent form has a subform based on a 4th table...
5
by: munkee | last post by:
All, I want to reference a button on the parent form of a subform. The parent however could be two different form names. frmlog frmcorrective How do I check which form is loaded in order...
2
by: Ryno Bower | last post by:
I've got two forms called cashtransactions and cashtrndetail. I have created a code that when the cashtransactions form open, it fills in data and then it also creates an autonumber in the one...
12
by: switchof | last post by:
How can I populate the list box (list 2) in subform from a value selected in a list box (list 1) in parent form? I can put in the row source of list 2 a query to match a table's field to the list...
6
by: JPetersen | last post by:
I have a subform of all the customers for the day (limited info). I want to open the specific record on the parent form by clicking an action button, on a specific record, on the subform. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.