Button to incrementaly change a record value

SteveGr

Registered User.
Local time
Today, 23:10
Joined
Aug 2, 2002
Messages
65
Hi all,

I would like to have a button on my form that adjusts a number value of a record in my table by increments of + or - 1.

Anyone know how to acomplish this?

Thanks, Stevegr
 
Are you talking about just changing a number in one of the fields, or are you talking about the location of the record in the table?
 
Assuming that the number is of Type Number in the Table
Put this in the on click of the button

Sub NumIncBut_Click
Dim tempNum As Integer

tempNum = Me.FieldToChange
tempNum = tempNum + 1 'or tempNum = tempNum - 1 (depending)

Me.FieldToChange = tempNum

End Sub
 
Increment button

I would like to change the value of particular records in my table by + or - 1.
 
If the field is bound to the table, then the table will change on the fly.

If the field is unbound, then you will have to open the recordset in code, find the desired record (using the "seek" method), and change the field value manually.

Like this:


Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("tblRma")
With rst

.Index = "yourFieldToSearch" 'Table Field to Search

.Seek "=", Forms!YourForm!YourControl 'Value to search for

If .NoMatch Then 'Record was not found
MsgBox ("This Record Does Not Exist!!")
Exit Function
Else
'MsgBox ("Found a Match, Your Control = " & !YourControl)
End If
.Edit
!YourField = Forms![YourForm]![YourField] 'set the table field equal to the new form value
.Update

End With


Good luck
 

Users who are viewing this thread

Back
Top Bottom