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

Saving the current record through VB 1

Status
Not open for further replies.
Sep 11, 2002
49
GB
Ok, I'm a real noob to this, but hopefully there's a simple answer.

I have a ADP front end to an SQL 2000 backend. I have a form with a button on it which I would like to save the current record - i.e. update SQL with the current record's information as it would if I navigated away and came back.

What's the command in the VB event procedure for this?

Told you it was something simple!

Thanks,
Patrick
 
If the form is bound:
DoCmd.RunCommand acCmdSaveRecord should work.

If not bound, you need to:
1: detect the record ID
2: run an Update SQL Statement (stored procedure or execute an SQL built in code):

strSQL = "Update TableName Set [field1] = " & Me("Field1") & ", [field2]= '" & Me("Field2") & "', [field3] = " ....
YourConnection.Execute strSQL


You need to have the appropriate permissions for TableName on SQL Server to be able to run such statements from the client.


[pipe]
Daniel Vlas
Systems Consultant

 
Thanks, that's great, but I have one issue with it.

It was a bound form and the "DoCmd.RunCommand DoCmdSaveRecord" sting worked, but here's the problem:

I am working on (say) record 5.

It's bound to an AfterUpdate property on a combo box.

I update the combo box, the record saves.

Then it flicks back to record 1.

I imagine the solution is to get the current record number, perform the save, then goto that record again. What is the code for that please?

Cheers for your help,
Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top