Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / January 2005

Tip: Looking for answers? Try searching our database.

Problem with form activate event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mattias - 05 Dec 2004 09:55 GMT
Hi

I have the below Form_activate event running in a orderform.
From the orderform I open a payment form..when done I close the payment form
and the orderform activates again..running the below to set the paymentstatus
of the current order. It works fine...however when opening the orderform for
the first time  something odd happens in the first record..without having
"activating" the form just opened it...it sets the status to 12..only the
first record being current..

Anyone know what is wrong about this...

Thank you in advance

Mattias

Private Sub Form_Activate()
Me.Recalc
If (Me!Total2 = Me!Total) Then
Me!Status = 13
End If
If (Me!Total2 < Me!Total) Then
Me!Status = 12
End If
If (IsNull(Me!Total2)) Then
Me!Status = 10
End If
End Sub
Rob Oldfield - 05 Dec 2004 10:27 GMT
I'm not sure exactly what you mean.... the activate event _is_ fired by
opening a form - from help:

"When you first open a form, the following events occur in this order:
Open ? Load ? Resize ? Activate ? Current"

You could drop a breakpoint into your routine and check to see what it
thinks 'Me' is.  It also seems to me that your logic is a bit out... if you
have something that you want to do when the payment form closes, then why
not attach it to that close event?

> Hi
>
[quoted text clipped - 24 lines]
> End If
> End Sub
Mattias - 05 Dec 2004 10:55 GMT
Hi

Cannot have it on the payment form close as it is not a unique
payment...every order can have sevaral payments linked via the
orderno(invoiceno.). So the of the order can be paid in full, not paid,
partly paid etc etc.

Just tried to comment the me.recalc line and the odd behavior when opening
the form dissapered..but on the other hand the activate  event did not set
the paymentstatus at all anymore!?

Mattias

> I'm not sure exactly what you mean.... the activate event _is_ fired by
> opening a form - from help:
[quoted text clipped - 38 lines]
> > End If
> > End Sub
Rob Oldfield - 05 Dec 2004 12:53 GMT
I still don't get what it is that you're trying to achieve.  What are the
total fields?  Do they depend upon data entered into the payment form?  Do
they depend upon other entries entered previously onto the payments table
(whether via the payments form or not)?  What is the me.recalc supposed to
do?

> Hi
>
[quoted text clipped - 51 lines]
> > > End If
> > > End Sub
Mattias - 05 Dec 2004 17:03 GMT
Hi Rob

Total is the order sum to be paid and total2 = Paid up to now. They are both
calculated fields (currency) in the form.
I have a hidden subform showing and summing all payments ..it is from this
subform where total2 get its value.

I want to set the paymentstatus at once after having added a payment to the
current record.

Mattias

> I still don't get what it is that you're trying to achieve.  What are the
> total fields?  Do they depend upon data entered into the payment form?  Do
[quoted text clipped - 63 lines]
> > > > End If
> > > > End Sub
Rob Oldfield - 05 Dec 2004 17:57 GMT
Hmmm.  I don't see why you need the hidden subform, and it might well be
that that's is the thing causing you problems.  Me.Recalc isn't going to
update anything if it depends upon code running via another form.  Two
ideas...

You could just base the Order form on a query that does the calculation...
group by all the Order fields, and sum the amounts from the Payment
fields... if you do that then a requery (in the close event of the payment
form) is going to work.  (Although it'll make all the fields read-only and
the requery will take you back to the first record)

Second way (and the one that I think I'd go for) would be just to drop
something like this into the close event of the payment form...

dim tot2 as whatever
tot2=dsum("[Amount]","Payments","[OrderID]="+cstr(me.orderid))
forms!orders!tot2=tot2
if forms!orders!total>tot2 then
   forms!orders!status="Set lawyers on to customer"
elseif forms!orders!total<tot2
   forms!orders!status="Pocket the spare cash"
.
.
end if

> Hi Rob
>
[quoted text clipped - 75 lines]
> > > > > End If
> > > > > End Sub
Mattias - 06 Dec 2004 16:29 GMT
Hi Rob

Sorry for this late reply and thank you for your suggestion.
There is no code in the subform only a txt control in the subforms footer
summing the payments.

So total2 (paid up to now only has as its
recordsource:=PaymentsSub!SubtotalAmount)

I tried your second suggestion in the paymentforms close event. Somehow it
does not update the order first time I close it....need to open payment form
a second time and close then it has updated the orderpaymentstatus.

What can be wrong here.

Mattias

> Hmmm.  I don't see why you need the hidden subform, and it might well be
> that that's is the thing causing you problems.  Me.Recalc isn't going to
[quoted text clipped - 115 lines]
> > > > > > End If
> > > > > > End Sub
Rob Oldfield - 06 Dec 2004 17:35 GMT
I'd guess that your original method was failing because the recalc wasn't
updating the subform correctly (requerying would be more likely to work),
but I still prefer the second way.

If you add a breakpoint into the code for the payments form, then can you
see the correct figure being calculated the first time the form closes?  It
should work without any need to refresh the display.

> Hi Rob
>
[quoted text clipped - 132 lines]
> > > > > > > End If
> > > > > > > End Sub
Mattias - 06 Dec 2004 19:31 GMT
Hi Rob

I do need this subform in the order form.
Right now I have the below in the paymentform
with this code I need to open and close the paymentform a second time to
make it enter the statusno in the orderform

Private Sub Form_Close()
Dim Total As Currency
Dim Total2 As Currency
Dim Status As Long

If Forms!Order!Total2 =Forms!Order!Total Then
Forms!Order!Status = 13
End If
If Forms!Order!Total2 < Forms!Order!Total Then
Forms!Order!Status = 12
End If
If (IsNull(Forms!Order!Total2)) Then
Forms!Order!Status = 10
End If
   
End Sub

Based on this ..do you know what to do now.

> I'd guess that your original method was failing because the recalc wasn't
> updating the subform correctly (requerying would be more likely to work),
[quoted text clipped - 157 lines]
> > > > > > > > End If
> > > > > > > > End Sub
Rob Oldfield - 06 Dec 2004 22:12 GMT
Couple of things....

Why do you think you need the subform?  (....that's assuming that the one
that you're talking about is the same one that I'm thinking about... the
hidden one?)

The subform won't do anything in the code you're attached because it's not
being told to.   What happens if you drop in a...

forms!order!subformcontrolname.requery

...after the dim statements in the close routine?

I'm beginning to suspect that there's something wrong with the way you're
linking the data entered on the payments form back to the original order.
What code are you using to open that?  (i.e. how does the payment form know
that it's linked back to the order?)

And I'd still like to know what
dsum("[Amount]","Payments","[OrderID]="+cstr(me.orderid)) is producing when
you first close the payments form.

<snipping the rest of the thread as it's getting a bit cumbersome
Mattias - 07 Dec 2004 13:31 GMT
Hi again.

I removed the subform now!! Tried your original idea to sum the payments in
the paymentform close event. But to make it work completly I had to ad sum
creditcardfee and curryency exchange fee. I also added a nz to be albe to
handle null values.

For the first time it set paymentstatus ok for the current record...but
since removing the subform it does not keep the values in the unbound
controls Total2, Creditcardfee and CurrencyExchangefee, when I go to the next
record and back again...the only value being saved and still correct is the
bound Status
control.

Tried one idea I had..added Total2, Creditcardfee and CurrencyExchangefee to
the ordertable and the form controls bound to the new fields. It saves the
values ok but it does not change the status anymore...

Mattias
Private Sub Form_Close()
Dim Total As Currency
Dim Total2 As Currency
Dim Status As Long
Dim CurrencyExchangeFee2 As Currency
Dim CreditcardFee2 As Currency

Total2 = DSum("[Amount]", "Paymentsqry", "[Orderno]=" + CStr(Me.Orderno))
Forms!Order!Total2 = Nz([Total2])
Creditcardfee2= DSum("[creditcardfee]", "Paymentsqry", "[Orderno]=" +
CStr(Me.Orderno))
Forms!Order!Creditcardfee = Nz([Creditcardfee2])
CurrencyExchangeFee2= DSum("[CurrencyExchangeFee]", "Paymentsqry",
"[Orderno]=" + CStr(Me.Orderno))
Forms!ExpeditionUtlämning!CurrencyExchangeFee = Nz([CurrencyExchangeFee2])
If Forms!Order!Total2 =Forms!Order!Total Then
Forms!Order!Status = 13
End If
If Forms!Order!Total2 < Forms!Order!Total Then
Forms!Order!Status = 12
End If
If (IsNull(Forms!Order!Total2)) Then
Forms!Order!Status = 10
End If
   
End Sub

> Couple of things....
>
[quoted text clipped - 19 lines]
>
> <snipping the rest of the thread as it's getting a bit cumbersome
Rob Oldfield - 07 Dec 2004 17:46 GMT
Hmmm.  Can't see how that's not working.  Try stepping through the code....
if you're setting Total2 to 10, for example, and Total is 20... then it must
work.

(Just in case you don't know how.... put the cursor on the If
Forms!Order!Total2 =Forms!Order!Total Then line... hit F9 to toggle a
breakpoint.... go through attempting to use the code and it will stop at
that line... hit F8 to move to the next line.... or F5 to carry on as usual)

Where does it go?  Does it get to the Forms!Order!Status = 13 line?

> Hi again.
>
[quoted text clipped - 65 lines]
> >
> > <snipping the rest of the thread as it's getting a bit cumbersome
Mattias - 07 Dec 2004 18:13 GMT
Hi Rob

Did you mean I should run the code bound or unbound case?

> Hmmm.  Can't see how that's not working.  Try stepping through the code....
> if you're setting Total2 to 10, for example, and Total is 20... then it must
[quoted text clipped - 86 lines]
> > >
> > > <snipping the rest of the thread as it's getting a bit cumbersome
Mattias - 07 Dec 2004 18:41 GMT
Rob

Tried the bound one. It did run throw the code all the way. The one I want
set to 13 had the value 10 but did not change it....

Mattias

> Hmmm.  Can't see how that's not working.  Try stepping through the code....
> if you're setting Total2 to 10, for example, and Total is 20... then it must
[quoted text clipped - 86 lines]
> > >
> > > <snipping the rest of the thread as it's getting a bit cumbersome
Rob Oldfield - 08 Dec 2004 08:09 GMT
So you're saying that when you run through the code where, for example, the
total field is 10, and the total of the payments is also 10, that it's
correctly figuring out that total2 is also 10, that it is actually getting
to the line Forms!Order!Status = 13 but that the form is still showing a 10?

That can't possibly happen.

Would it be possible to zip the db up (removing any large chunks of data
where not required) and mail it to me?

> Rob
>
[quoted text clipped - 52 lines]
> > > "[Orderno]=" + CStr(Me.Orderno))
> > > Forms!ExpeditionUtl?mning!CurrencyExchangeFee =
Nz([CurrencyExchangeFee2])
> > > If Forms!Order!Total2 =Forms!Order!Total Then
> > > Forms!Order!Status = 13
[quoted text clipped - 37 lines]
> > > >
> > > > <snipping the rest of the thread as it's getting a bit cumbersome
Mattias - 08 Dec 2004 08:49 GMT
Ok thank you!!

How big maximum and where to..?

Mattias

> So you're saying that when you run through the code where, for example, the
> total field is 10, and the total of the payments is also 10, that it's
[quoted text clipped - 121 lines]
> > > > >
> > > > > <snipping the rest of the thread as it's getting a bit cumbersome
Rob Oldfield - 08 Dec 2004 13:26 GMT
As long it's not absolutely massive, then don't worry about the maximum....
zen13426 followed by one of those strange @ symbol things followed by
zen.co.uk (just avoiding it getting picked up by any of those nasty spam
harvesting bots)

> Ok thank you!!
>
[quoted text clipped - 127 lines]
> > > > > >
> > > > > > <snipping the rest of the thread as it's getting a bit cumbersome
Mek - 28 Jan 2005 22:07 GMT
Your problem is due to the fact that the first Activate event fires before
the form becomes visible on the screen.  Admittedly, this is idiotic, but
then Microsoft is idiotic and Access is a piece of crap, so what's the
surprise?

> Hi
>
[quoted text clipped - 24 lines]
> End If
> End Sub
John Nurick - 29 Jan 2005 10:34 GMT
Hi Mattias,

Mek's not quite correct: the problem is caused by the fact that the
Activate event fires whenever the form becomes active (it's irrelevant
in this context whether it's visible or not) and not just when you
switch to it from the payment form. That's hardly idiotic behaviour
(although it's not always obvious what counts as "becoming active" and
therefore when the event will file).

In this situation, it's best to set the paymentstatus explicitly from
the payment form. If the payment form has an OK button, the button's
Click event procedure would be the place to do it. Otherwise, the
payment form's Close event procedure.

>Your problem is due to the fact that the first Activate event fires before
>the form becomes visible on the screen.  Admittedly, this is idiotic, but
[quoted text clipped - 29 lines]
>> End If
>> End Sub

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.