Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code misses reading field value

Status
Not open for further replies.

AJParkinson

Technical User
Apr 11, 2003
74
GB
This is driving me crazy.
Basically - I have a checkbox on a form that when ticked opens a second form. Various functions are performed and values are written to this form and into variables. From this form the variables are passed back and used to populate additonal fields on the first form...
All except on field/variable! This field is a sum field on the second form. The value of this field is written to the variable and passed back as with the others, however when reading this variable back into a field on the first form I get a type mismatch error, and the code halts - (the variable is not populated) - if I reset the next statement line back 2 lines to re-read the second form field value, then continue to run the code, everything works.
If I put a breakpoint in just before it initally reads the field and F8 through it, it works fine - take the breakpoint back out and it errors again! It appears to be a timing issue -

Code:
PFterritory = Trim(Forms!pf_contrib_sub.Form!territory.text)
Forms!pf_contrib_sub.Form!order_qty.SetFocus
PFQty = Trim(Forms!pf_contrib_sub.Form!order_qty.text)
Forms!pf_contrib_sub.Form!product.SetFocus
PFpassy = Trim(Forms!pf_contrib_sub.Form!product.text)
Forms!pf_contrib_sub.txtSumVal.SetFocus
[COLOR=red]PFOSum = Forms!pf_contrib_sub.txtSumVal.text[/color]  [COLOR=green]'code breaks at this point[/color]
GetPFBase
GetPFSize
GetPFBand

Any ideas greatly appreciated...

Andrew
 
Have you tried this ?
PFOSum = Forms!pf_contrib_sub.txtSumVal.Value

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Yes, when I use .Value instead of .Text, the code runs through without error, but no actual value is read into the variable - PFOSum remains at '0'

Little more info if this helps:
PFOSum is declared as Currency

On the form - the textbox named as txtSumVal has control source as - =Sum([Value]) and has its format is set as currency

On the form - the textbox named as val has control source as - Value: IIf([order_qty]=0,"",[val]) - from its undelying query, val is a double in the linked table that the query reads.
 
PHV, revisited my code and changed all related .text for .value

Code runs through without breaking ~ but the actual value returned is always 0 - unless I put a breakpoint in, then it returns the expected (correct) value

On the surface it seems to be a timing issue. I've put in a simple For/Next loop to pause but this doesn't make any difference. I also suspected that it may be something to do with the value being calculated on the form, and if the form hadn't been drawn on screen yet then how could the calculation take place ~ not so, I have added code to calculate the expected total from values held before the form is drawn... it still returns 0 unless a breakpoint is added

 
HAve you tried this, before to grab the value ?
Forms!pf_contrib_sub.txtSumVal.ReQuery

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV - no luck there.
I'm limited with time now and I've had to try approaching it from a different angle, rather than letting the form add the totals then reading that, I've rejigged a couple of my underlying queries to come up with the total prior to the form load. This approach is working, so I'm running with it!

Many thanks for your help and suggestions, Its helped me learn a thing or two during the course of this problem
 
have you tried sticking a'DoEvents'line in just before you retrieve the value,
ie;
....
DoEvents
PFOSum = Forms!pf_contrib_sub.txtSumVal.Value
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top