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!

Default Question

Status
Not open for further replies.

fmaca

Technical User
Apr 24, 2002
16
CA
Good morning all.

I have a form to enter parts into inventory. The first box is the part number. The second is "Quantity Good" with a default value of 1. The third is "Quantity Broken" with a default of 0. I am trying to get the default to be linked to the "Quantity Good" value with =IIf([Quantity Good]),1,1,0 This is not working. What am I doing wrong?

Thanks is advance.

Ethan
 
Your syntax is incorrect. It should look something like this:

=IIF([Quantity Good],1,0)

The IIF statement looks like this:

IIf(expr, truepart, falsepart)
 
Thanks for the response.

I tried =IIf([QuantityGood]=0,1,0) and it still doesn't work. I also tried =IIf([QuantityGood]="0","1","0"). What am I missing?

Ethan
 
Hi fmaca,

What type is 'Quantity Good'? Is it numeric or Yes/No, what?

If it's a Yes/No (boolean), then you are checking for 1 for True and 0 for False - right?

True actually is -1.

Stoopid ain't it?

Regards,

Darrylle








"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Hi

It may be that the field contains a null or empty value in which case the following should help:

IIf(IsNothing([QuantityGood]) or [QuantityGood] = 0,1,0)

The code for the ISNothing() function follows
'----------------------------------------------------------
' IsNothing
'
' Purpose:
' Detect Empty, Null and zero length strings and variants
'
' Returns: True if empty/blank/Null, otherwise False
'
' Comments: This is one of our most commonly used
' functions since it
' doesn't require us to convert Nulls.
'----------------------------------------------------------
Function IsNothing(v As Variant) As Integer
'----------------------------------------------------------
'Compare the passed variable to the
'Variant Intrinsic Constants
Select Case VarType(v)
Case V_EMPTY
IsNothing = True
Case V_NULL
IsNothing = True
Case V_STRING
If Len(v) = 0 Then
IsNothing = True
End If
Case Else
IsNothing = False

End Select

End Function
 
Hi,

Check the value with a msgbox statement in the <On Open> event of the form or some other suitable event.

e.g. msgbox [Quantity Good]

If you've named the form textbox differently, then better to use that (in fact - check the name of the textbox).

Regards,

Darrylle

&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
I checked the name of the textbox and it's OK. Should I look at the focus stuff?

I guess the question is should the default change when I get to the box or when I leave it. I'm assuming that it will change from 0 to 1 as soon as I tab in to the box. Maybe I'm wrong and it should change when I tab out of the box. That would be a little weird though, not seeing the value until after you've left the textbox.

Ethan
 
Hi,

Can we first clarify this? (We don't seem to be getting anywhere).

You say &quot;I am trying to get the default to be linked to the &quot;Quantity Good&quot; value with ...&quot;

Default of what?
'linked' to 'Quantity Good' - why?
Why 'link' a default value to an actual value?

What EXACTLY are you trying to do?

Regards,

Darrylle


&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
I will try to explain.

There are 4 textboxes on the form in this order: PartNumber, QuantityGood, QuantityBroken and Location.

The part number is entered in, then each of the quantities and finally the location. I have specified a default for the location so in the best case the part number is entered followed by hitting the enter key 4 times.

The defaults are 1 for QuantityGood and 0 for Quantity Broken.

If I change the QuantityGood number to 0 I'd like the default for QuantityBroken to change to 1.

All values are numeric.

Hope I've explined it better this time.

Ethan
 
Try this:
In the AfterUpdate event of QuantityGood, add the following

Private Sub QuantityGood_AfterUpdate()

If (QuantityGood = 0) Then QuantityBroken = 1

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top