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

command button query

Status
Not open for further replies.

balllian

MIS
Jan 26, 2005
150
GB
Is it possible on saving a record in a form you have entered details to update a value in a table to a different value for example from 1 to 2.



 
You can use the After Update event of the form to run a query, or run SQL from code, or update a recordset. If that is what you mean.
 
i have a default value in the table for the newly created record of which i need to change from '1' to '2' to show that this has been updated successfully.

I have a save button on the form of which i would like to attach this code to.

This is the current code i have.

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub
 
Here are some notes:

Code:
Private Sub Command3_Click()
'It is best to name controls properly, cmdSave, for example

On Error GoTo Err_Command3_Click

'PWise's version is better, this version is dprecated by MS
    'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
docmd.RunCommand acCmdSaveRecord 

Exit_Command3_Click:
    Exit Sub

Err_Command3_Click:
    MsgBox Err.Description
    Resume Exit_Command3_Click
    
End Sub

Furthermore, if the form is bound to a recordset, the default action is to save, the problem is preventing saves.

To set a field to 2, add it as a control, hidden, if you wish, then set the value in the Before Update event:

[tt]Me.ControlName = 2[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top