Save button code not realy save?

H

Harmannus

Hallo,

I have made a save button with the code:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

If i edit a record and save it by clicking the save button "and" stay in
this record i noticed the record is not realy saved/updated! How can realy
save a record i have edited?

Thanx for any tips!

Regards,

Harmannus
 
R

Rick Brandt

Harmannus said:
Hallo,

I have made a save button with the code:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

If i edit a record and save it by clicking the save button "and" stay in
this record i noticed the record is not realy saved/updated! How can realy
save a record i have edited?

How are you determining that the record is not "really saved"?

What you have there is an old syntax that is only supported for backwards
compatibility. The newer, preferred code would be...

DoCmd.Runcommand acCmdSaveRecord

or

Me.Dirty = False
 
H

Harmannus

Hallo,

Thanx for the tip!

i have the below code running through my records.

Private Sub LockUnlock(LockIt As Boolean)

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl

End Sub

Changing the statusID to 2 and saving but stay in the changed record still
allows me to edit the record....

Private Sub Form_Current()

If Me![StatusID] = 1 Then
Me.AllowDeletions = False
LockUnlock True
Else
Me.AllowDeletions = True
LockUnlock False
End If

End Sub

Any suggestions on how to get it to update the records instantly?

Regards,

Harmannus
 
J

John Vinson

Hallo,

I have made a save button with the code:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

If i edit a record and save it by clicking the save button "and" stay in
this record i noticed the record is not realy saved/updated! How can realy
save a record i have edited?

Two ways:

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty = True Then Me.Dirty = False
 
H

Harmannus

Hallo,

Thanx for the respons! No effect. Please see previous message.

Is there also other code for undo?

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Regards,

Harmannus
 
D

Douglas J. Steele

AFAIK, the Current event requires you to actually move to a new record.
Saving doesn't invoke the Current event.

Since you're saving through code, call LockUnlock immediately after you save
the record.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Harmannus said:
Hallo,

Thanx for the tip!

i have the below code running through my records.

Private Sub LockUnlock(LockIt As Boolean)

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl

End Sub

Changing the statusID to 2 and saving but stay in the changed record still
allows me to edit the record....

Private Sub Form_Current()

If Me![StatusID] = 1 Then
Me.AllowDeletions = False
LockUnlock True
Else
Me.AllowDeletions = True
LockUnlock False
End If

End Sub

Any suggestions on how to get it to update the records instantly?

Regards,

Harmannus




Rick Brandt said:
How are you determining that the record is not "really saved"?

What you have there is an old syntax that is only supported for backwards
compatibility. The newer, preferred code would be...

DoCmd.Runcommand acCmdSaveRecord

or

Me.Dirty = False
 
H

Harmannus

Hallo,

Thanx for the response!

I placed the below code on the form itself.

Private Sub LockUnlock(LockIt As Boolean)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl
End Sub

Do i have to move the code to a module and use function when calling "call
LockUnlock" on the form?

Regards,

Harmannus


Douglas J. Steele said:
AFAIK, the Current event requires you to actually move to a new record.
Saving doesn't invoke the Current event.

Since you're saving through code, call LockUnlock immediately after you save
the record.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Harmannus said:
Hallo,

Thanx for the tip!

i have the below code running through my records.

Private Sub LockUnlock(LockIt As Boolean)

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl

End Sub

Changing the statusID to 2 and saving but stay in the changed record still
allows me to edit the record....

Private Sub Form_Current()

If Me![StatusID] = 1 Then
Me.AllowDeletions = False
LockUnlock True
Else
Me.AllowDeletions = True
LockUnlock False
End If

End Sub

Any suggestions on how to get it to update the records instantly?

Regards,

Harmannus




Rick Brandt said:
Hallo,

I have made a save button with the code:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

If i edit a record and save it by clicking the save button "and"
stay
 
D

Douglas J. Steele

I see no reason not to have that sub in the form itself. What I was
suggesting is that rather than simply having

DoCmd.Runcommand acCmdSaveRecord

you should put

DoCmd.Runcommand acCmdSaveRecord
If Me![StatusID] = 1 Then
Me.AllowDeletions = False
LockUnlock True
Else
Me.AllowDeletions = True
LockUnlock False
End If

or

DoCmd.Runcommand acCmdSaveRecord
Call Form_Current()

On the other hand, you could easily make that routine a little more generic
by putting it in a module and changing it to

Private Sub LockUnlock(WhatForm As Form, LockIt As Boolean)
Dim ctl As Control
For Each ctl In WhatForm.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl
End Sub

and invoke it as

LockUnlock Me, True

or

Call LockUnlock(Me, True)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)

Harmannus said:
Hallo,

Thanx for the response!

I placed the below code on the form itself.

Private Sub LockUnlock(LockIt As Boolean)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl
End Sub

Do i have to move the code to a module and use function when calling "call
LockUnlock" on the form?

Regards,

Harmannus


Douglas J. Steele said:
AFAIK, the Current event requires you to actually move to a new record.
Saving doesn't invoke the Current event.

Since you're saving through code, call LockUnlock immediately after you save
the record.

Harmannus said:
Hallo,

Thanx for the tip!

i have the below code running through my records.

Private Sub LockUnlock(LockIt As Boolean)

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = LockIt
On Error Resume Next
End If
Next ctl

End Sub

Changing the statusID to 2 and saving but stay in the changed record still
allows me to edit the record....

Private Sub Form_Current()

If Me![StatusID] = 1 Then
Me.AllowDeletions = False
LockUnlock True
Else
Me.AllowDeletions = True
LockUnlock False
End If

End Sub

Any suggestions on how to get it to update the records instantly?

Regards,

Harmannus




Hallo,

I have made a save button with the code:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

If i edit a record and save it by clicking the save button "and"
stay
in
this record i noticed the record is not realy saved/updated! How can
realy
save a record i have edited?

How are you determining that the record is not "really saved"?

What you have there is an old syntax that is only supported for backwards
compatibility. The newer, preferred code would be...

DoCmd.Runcommand acCmdSaveRecord

or

Me.Dirty = False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top