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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a negative number from a form

Status
Not open for further replies.

gearhead03

Technical User
Mar 29, 2003
147
US
I am setting up a check register. I want enter a positive number on a form (the "check" form) and have it entered as a negative number in the "register" table. Is this possible? If so please explain.

Thanks in advance

Mark A. Kale
 
Couldn't you do
Me![NegBoxName].value = 0 - [Forms]![FormName]![PosName]
on the OnOpen event of the form?
 
Read your question too fast. Thought the it said "register" form. You want it direct to the table. On the AfterUpdate of the positive box, you could do:(In my example, CheckID is the Primary Key of your table)

Private Sub ControlName_AfterUpdate()
Dim DB As Database
Dim RS As Recordset
Dim strWhere As String

Set DB = CurrentDb()
Set RS = DB.OpenRecordset("RegisterTable", dbOpenDynaset)
strWhere = "[CheckID] = " & Chr(34) & Me![CheckID] & Chr(34)
RS.FindFirst strWhere
If RS.NoMatch Then
MsgBox "No match found"
Else
RS.Edit
RS![NegFieldName] = 0 - Me![PosFieldName]
RS.Update
End If
RS.Close
DB.Close
Set RS = Nothing
Set DB = Nothing
End Sub

If CheckID is a numeric, the strWhere looks like
strWhere = "[CheckID] = " Me![CheckID]
 
Last line should be:
strWhere = "[CheckID] = " & Me![CheckID]

I really should take my time.

But the code works.
 
Why not simply this in the BeforeUpdate event procedure of the control ?
If IsNumeric(Me![name of control]) Then Me![name of control] = -Abs(Me![name of control])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top