what does the AfterUpdate event do

ryetee

Registered User.
Local time
Today, 23:11
Joined
Jul 30, 2013
Messages
952
Reason I ask is that I assumed that something happened after an update took place.

After a field is entered on a form I use the afterupdate event to load another form with the intention of using key from the updated record to run a query which is used to load data onto the loaded form.

I enter data in the field and the update event loads the new form which is blank. It appears there has been no update after all.

Any help appreciated.
 
hello,

Can you show your code to load another form?

Yes,

If Me.[Component ID] = 1 Then


args = Me.txtEmpName & "|" & Me.txtRMANo & "|" & Me.txtComponentPartNo & "|" & _
Me.txtSerialNo & "|" & Me.txtJobID & "|" & Me.txtDescription & "|" & _
Me.txtEmpID & "|" & Me.txtID
DoCmd.OpenForm "Component Swaps", , , "[ID]= " & Me.txtID & "", , , args ''

End If



btw Me.txtID is an integer
 
May be you have code on the Open or OnLoad events of the second form as you use the OpenArgs argument ?
 
I think this line doesn't look right to me;
DoCmd.OpenForm "Component Swaps", , , "[ID]= " & Me.txtID & "", , , args ''

I think it should be
DoCmd.OpenForm "Component Swaps", , , "[ID]= " & Me.txtID , , , args
without the extra quotes?
 
I think this line doesn't look right to me;

I think it should be
DoCmd.OpenForm "Component Swaps", , , "[ID]= " & Me.txtID , , , args
without the extra quotes?

I can take out the "" but it's only sticking nothing after the Me.txtID. It was a hangover as to when txtID was a string. I'll give it a whirl.
 
I think this line doesn't look right to me;

I think it should be
DoCmd.OpenForm "Component Swaps", , , "[ID]= " & Me.txtID , , , args
without the extra quotes?
I do but not sure why that would stop things happening.
 
Can you post your code that runs from the open args statement on the component swaps form?
 
Can you post your code that runs from the open args statement on the component swaps form?
if you're talking about the forms load event then

Dim argString() As String
Dim strStatus As String
blnCancel = False

If Not IsNull(Me.OpenArgs) Then
argString = Split(Me.OpenArgs, "|", 10)
Me.txtEmpName = argString(0)
Me.txtRMANo = argString(1)
Me.txtComponentPartNo = argString(2)
Me.txtSerialNo = argString(3)
Me.txtJobID = argString(4)
Me.txtDescription = argString(5)
Me.txtEmpID = argString(6)
End If
 
I would check that your argString split is working by debug.print them in order as they are fired. I would assume if the form is blank then the values aren't being passed.

It occurs to me however that if most of this data is already stored you probably don't need to enter it on another form ?

You also mentioned a query in your first post - how does that fit in with this process?
 
I would check that your argString split is working by debug.print them in order as they are fired. I would assume if the form is blank then the values aren't being passed.

It occurs to me however that if most of this data is already stored you probably don't need to enter it on another form ?

You also mentioned a query in your first post - how does that fit in with this process?

Right I've changed all this round now and still it's not working.

This is what I have now.
I have a form which displays records from a table in a continuous way (like a spreadsheet).
When the first field (of each line) is added the AfterUpdate event is kicked off and it is checked for certain conditions and if they apply then a second form is loaded.

If Me.[Component ID] = 1 Then

args = Me.txtEmpName & "|" & Me.txtRMANo & "|" & Me.txtComponentPartNo & "|" & _
Me.txtSerialNo & "|" & Me.txtJobID & "|" & Me.txtDescription & "|" & _
Me.txtEmpID & "|" & Me.txtID & "|" & Me.txtCustomer & "|" & Me.Component_Part_No

DoCmd.OpenForm "Component Swaps", , , , , , args

End If

I pass over, amongst other things, the ID from table 1 which is a foreign key to a second table. This is defined as Me.txtID.
The 2nd forms fills in parts of the form from the data passed over leaving the user to fill in about 3 fields himself.

The load event on the second form contains
If Not IsNull(Me.OpenArgs) Then
argString = Split(Me.OpenArgs, "|", 11)
Me.txtEmpName = argString(0)
Me.txtRMANo = argString(1)
Me.txtComponentPartNo = argString(2)
Me.txtSerialNo = argString(3)
Me.txtJobID = argString(4)
Me.txtDescription = argString(5)
Me.txtEmployeeID = argString(6)
Me.txtEmpID = argString(6)
Me.txtJobPartID = argString(7)
Me.txtCustomer = argString(8)
Me.ModelNumber = argString(9)
Me.txtSwapDate = Now()
End If


Now I've step through all of this and all the fields are populated with the right values.
When the user comes to save this (via a button) I get an error message stating "you can not add or change a record because a related record is required in table "X"

I presumed that the table had been updated as the after update event occurred.
The data from the 1st form comes from a query rather than a table itself, but I though if data was updated in a query it was reflected in the table itself.

Hope this is all clear
 
I think I can see what you are trying to achieve but I think you are going about it very "obtusely", I think you need to look at how you are storing your data.

Is your Goal this - You have an item that is assigned to a user/client/customer/department, and you want to reassign it to another user or department?
 
I think I can see what you are trying to achieve but I think you are going about it very "obtusely", I think you need to look at how you are storing your data.

Is your Goal this - You have an item that is assigned to a user/client/customer/department, and you want to reassign it to another user or department?

No!!

It's all about repairs (a Job)
A repair can have many parts that are changed.
One part, in particular, can need to be changed more than once even in the same job and even if it doesn't extra information is needed about it.
So we have
Job 1 has say five parts Part1 thru Part5. But Part3 doesn't work to Part6 is used instead. In fact Part6 might not work either and has to be replaced Part7. I need to keep information about Part3, Part6 and Part7 separately.

So I start off with
JOB 1 Part1
JOB 1 Part2
JOB 1 Part3
JOB 1 Part4
JOB 1 Part5

When Part3 is entered the system knows it is of a kind that more information is required and form 2 is loaded and that information stored. Then as above Part6 and Part7 are used to replace Part3.

So(!), we end up with on the parts table
JOB 1 Part1
JOB 1 Part2
JOB 1 Part7
JOB 1 Part4
JOB 1 Part5

Now the ID for the Part that was changed lets call it ID3 will utlimately have 3 entries on what I'll call the swaps table which will now have

ID3 Part3 and various info about Part3
ID3 Part6 and various info about Part6
ID3 Part6 and various info about Part7

Clear as mud huh?

Anyway I've find the problem or at least something that clears it.
Before I call the 2nd form I do a Me.refresh.
This works but I'm sure it'll cause other problems (Me.undo may not work for example).
 
That does make sense, You are basically storing a list of parts used and a history on the parts that were removed.
Apologies - I was going to suggest a refresh having had re-read - but you have beaten me to it.

You won't be able to undo once refreshed, as you could be deleting the FK of the related record you have just created. You can however probably code a "undo" action if required.
 
That does make sense, You are basically storing a list of parts used and a history on the parts that were removed.
Apologies - I was going to suggest a refresh having had re-read - but you have beaten me to it.

You won't be able to undo once refreshed, as you could be deleting the FK of the related record you have just created. You can however probably code a "undo" action if required.

I know but funnily enough (from the code I inherited) there is a macro that does an undo record which seems to work!!
 

Users who are viewing this thread

Back
Top Bottom