Is this possible

M

myxmaster

I have a combo box with 2 choices , withdrawal or deposit. I then have
a field called amount. If the user selects deposit and then enters say
$1000 in the amount field, is it possible to make the default entry a
negative number ($-1000). I know I can have the user enter the number
as a negative however if they forget the minus key then the amount
will reflect as a positive number.

TIA
 
F

fredg

I have a combo box with 2 choices , withdrawal or deposit. I then have
a field called amount. If the user selects deposit and then enters say
$1000 in the amount field, is it possible to make the default entry a
negative number ($-1000). I know I can have the user enter the number
as a negative however if they forget the minus key then the amount
will reflect as a positive number.

TIA

Don't you also wish to assure that any Withdrawal is a positive
number?

Code the Amount control's AfterUpdate event:
If IsNull([ComboName]) Then
MsgBox "You Must select either Withdrawal or Deposit."
Exit sub
If Me.[ComboName] = "Deposit" Then
If Me.[Amount] >0 Then
Me.[Amount] = Me.[Amount] * -1
End If
Else
If Me.[Amount] < 0 Then
Me.[Amount] = Abs(Me.[Amount])
End If
End If
End If
 
A

Aaron Kempf

yeah.. with SQL Server you can have RULES that apply to a particular
datatype

so that if you want to reuse a particular constraint (such as money greater
than 0) you can define it once and use it in 100 different places

the concept is called 'code reuse'
and it's not possible with MDB



fredg said:
I have a combo box with 2 choices , withdrawal or deposit. I then have
a field called amount. If the user selects deposit and then enters say
$1000 in the amount field, is it possible to make the default entry a
negative number ($-1000). I know I can have the user enter the number
as a negative however if they forget the minus key then the amount
will reflect as a positive number.

TIA

Don't you also wish to assure that any Withdrawal is a positive
number?

Code the Amount control's AfterUpdate event:
If IsNull([ComboName]) Then
MsgBox "You Must select either Withdrawal or Deposit."
Exit sub
If Me.[ComboName] = "Deposit" Then
If Me.[Amount] >0 Then
Me.[Amount] = Me.[Amount] * -1
End If
Else
If Me.[Amount] < 0 Then
Me.[Amount] = Abs(Me.[Amount])
End If
End If
End If
 
M

myxmaster

I have a combo box with 2 choices , withdrawal or deposit. I then have
a field called amount. If the user selects deposit and then enters say
$1000 in the amount field, is it possible to make the default entry a
negative number ($-1000). I know I can have the user enter the number
as a negative however if they forget the minus key then the amount
will reflect as a positive number.

Don't you also wish to assure that any Withdrawal is a positive
number?

Code the Amount control's AfterUpdate event:
If IsNull([ComboName]) Then
MsgBox "You Must select either Withdrawal or Deposit."
Exit sub
If Me.[ComboName] = "Deposit" Then
If Me.[Amount] >0 Then
Me.[Amount] = Me.[Amount] * -1
End If
Else
If Me.[Amount] < 0 Then
Me.[Amount] = Abs(Me.[Amount])
End If
End If
End If

Hi Fred,
I pasted the code into the amount field and referenced the combobox
name (TransactionType) however when I select withdrawal or deposit
each amount is still reflected as a positive number. Any Ideas.
 
F

fredg

I have a combo box with 2 choices , withdrawal or deposit. I then have
a field called amount. If the user selects deposit and then enters say
$1000 in the amount field, is it possible to make the default entry a
negative number ($-1000). I know I can have the user enter the number
as a negative however if they forget the minus key then the amount
will reflect as a positive number.

Don't you also wish to assure that any Withdrawal is a positive
number?

Code the Amount control's AfterUpdate event:
If IsNull([ComboName]) Then
MsgBox "You Must select either Withdrawal or Deposit."
Exit sub
If Me.[ComboName] = "Deposit" Then
If Me.[Amount] >0 Then
Me.[Amount] = Me.[Amount] * -1
End If
Else
If Me.[Amount] < 0 Then
Me.[Amount] = Abs(Me.[Amount])
End If
End If
End If

Hi Fred,
I pasted the code into the amount field and referenced the combobox
name (TransactionType) however when I select withdrawal or deposit
each amount is still reflected as a positive number. Any Ideas.

Sorry, my goof.
An End If was in the wrong position.

Paste this into the [Transaction Type] AfterUpdate event.

If IsNull([Transaction Type]) Then
MsgBox "You Must select either Withdrawal or Deposit."
Exit sub
End If
If Me.[Transaction Type] = "Deposit" Then
If Me.[Amount] >0 Then
Me.[Amount] = Me.[Amount] * -1
End If
Else
If Me.[Amount] < 0 Then
Me.[Amount] = Abs(Me.[Amount])
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top