VBA Stopping from one event to another event??

SahilSS

New member
Local time
Today, 06:39
Joined
Nov 20, 2014
Messages
1
Hello,

Is it possible?? VBA Code is stopping from one AfterUpdate to another AfterUpdate event ??

I have created a invoice creation form & using DLOOKUP for customer details update purpose on AfterUpdate Event. That is CID and Customer fields...

Some times that fields are using manual entry without DLOOKUP because adding new customer details & Data modifying. So on the time no need to use DLOOKUP option on AfterUpdate event and need to stopping VBA from CID AfterUpdate event to Customer AfterUpdate event Or i need in the both of fields our choice wise.

that option i need under DCount condtion for both Procedures. Could you please help!

VBA:
Private Sub CID2_AfterUpdate()
On Error GoTo ErrorHandler

If DLookup("[TrNo]", "RelationsQry", "RID= '" & Me!CID2 & "'") Then
Me!CID1 = DLookup("[TrNo]", "RelationsQry", "RID= '" & Me!CID2 & "'")
Me!Customer = DLookup("[RName]", "RelationsQry", "RID= '" & Me!CID2 & "'")
Me!Address = DLookup("[Address]", "RelationsQry", "RID= '" & Me!CID2 & "'")
Me!TinNumber = DLookup("[TinNumber]", "RelationsQry", "RID= '" & Me!CID2 & "'")
Me!TownVLG = DLookup("[TownVLG]", "RelationsQry", "RID= '" & Me!CID2 & "'")
Else

Dim StrCriteria As String
StrCriteria = "CIDCST = '" & Trim((Me!CID2) & " " & Trim(Me!Customer)) & "'"

If DCount("*", "RelationsQry", StrCriteria) <= 0 Then
Me.CID1.Value = Null
Me.Customer.Value = Null
Me.Address.Value = Null
Me.TinNumber.Value = Null
Me.TownVLG.Value = Null
End If
' I need that option in this place
End If
ErrorHandler:
End Sub

----------------------------------------------------

Private Sub Customer_AfterUpdate()
On Error GoTo ErrorHandler

If DLookup("[TrNo]", "RelationsQry", "RName= '" & Me!Customer & "'") Then
Me!CID1 = DLookup("[TrNo]", "RelationsQry", "RName= '" & Me!Customer & "'")
Me!CID2 = DLookup("[RID]", "RelationsQry", "RName= '" & Me!Customer & "'")
Me!Address = DLookup("[Address]", "RelationsQry", "RName= '" & Me!Customer & "'")
Me!TinNumber = DLookup("[TinNumber]", "RelationsQry", "RName= '" & Me!Customer & "'")
Me!TownVLG = DLookup("[TownVLG]", "RelationsQry", "RName= '" & Me!Customer & "'")
Else

Dim StrCriteria As String
StrCriteria = "CIDCST = '" & Trim((Me!CID2) & " " & Trim(Me!Customer)) & "'"

If DCount("*", "RelationsQry", StrCriteria) <= 0 Then
Me.CID1.Value = Null
Me.CID2.Value = Null
Me.Address.Value = Null
Me.TinNumber.Value = Null
Me.TownVLG.Value = Null
End If
' I need that option in this place
End If
ErrorHandler:
End Sub
 
If you are asking whether it is possible to not fire (or not honor the firing of) a particular event, the answer is a guarded yes. You do that by having flags in your code that would be set by other parts of the code. Then, let the event fire as it will, but if the flag says "ignore this event" then you just jump to the end of the event code until that flag changes to a state that says "honor this event." This approach, though it sounds clunky, is FAR easier than reaching into the control's event list and mucking about in that mess of pointers. Stated another way, don't try to dynamically declare the event handler; instead just dynamically declare a flag that would make the handler do nothing when it fires.

I'll have to admit that your question was a bit vague, but I think that's what I got out of it. If I misunderstood what you wanted, please chalk that up to miscommunication on my part.
 

Users who are viewing this thread

Back
Top Bottom