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!

Command button Updating table

Status
Not open for further replies.

ITbully

MIS
Jul 17, 2003
2
US
How do you get a command button to update the table each time you click it.

I am working on a form where each time you hit the increment command button it adds 10 and enters the new number in the text box, but the only time the table will update is whenever I close the form.

I thought if I did an after update for the button, but then it will not keep my running total in the text box, it just clears it and starts over??

Any ideas???
 
Two solutions come to mind. The first, and probably easiest, is to save the record as soon as the increment button is clicked. You would just need a line of code like this:
Code:
DoCmd.RunCommand acCmdSaveRecord
Second, you could use an embedded SQL statement to update the table directly and then refresh the form to display the change.
Code:
Docmd.runSQL "UPDATE TableName SET Something = 10 WHERE PrimaryKey = "current record""
Docmd.Requery
Hope this helps!
 
Both of the suggestions did not work.. I am not sure why..

Here is a sample of my code:

Dim MyNewValue As Long



MyNewValue = Nz(txtIncrement2, 0) + 10
If (MyNewValue <= 10000) Then
Me.txtIncrement2 = MyNewValue
Else
MsgBox &quot;This application will close, it can not exceed 10,000&quot;, _
vbOK
DoCmd.Beep
DoCmd.Close

End If
DoCmd.Save


End Sub


Private Sub cmdReverse2_Click()
Me.txtReverse2 = StrReverse(Me.txtIncrement2)


End Sub

Private Sub cmdReverse2_GotFocus()
DoCmd.RunCommand acCmdSaveRecord
End Sub

Private Sub Form_Close()
DoCmd.GoToRecord , , acNewRec
End Sub


Let me know if I can answer any other questions...Your help is greatly appreciated...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top