"The data has been changed" when running a synchronize command

  • Thread starter Thread starter erick-flores
  • Start date Start date
E

erick-flores

Hello all

This is how my code looks:
Private Sub Email_send_report_Click()

CurrentDb.Synchronize ("path")
CurrentDb.Close

Dim stDocName As String

If MsgBox("Make sure your expense report is correct. Once you
click Yes, you will not be able to change any information. Click No to
go back.", vbYesNo, "Submit Report?") = vbYes Then
Me.CHECK = True
Me.Dirty = False
stDocName = "Expense Report"
DoCmd.SendObject acReport, stDocName, "snapshot format"
DoCmd.Close
Else
'do nothing
End If
End Sub

Whats happenin is, I am getting the "The data has been changed"
message when I click on this button. I need to click twice on this
button in order to send the email. 1st click: pop up meesage and 2nd
click: I can send it. I want to be able to send it un the first click.
What is weird ( and I say weird because I have no clue what happenin)
IF I remove these two lines:
CurrentDb.Synchronize ("path")
CurrentDb.Close
from my code everything works fine. But I MUST synchronize before I
send the e-mail.

Can somebody tell me how to get rid off that "The data has been
changed" message I tried to bypass it trapping the error but it didnt
work.

Thanks in advance
 
This is how my code looks:
Private Sub Email_send_report_Click()

CurrentDb.Synchronize ("path")
CurrentDb.Close

You should omit this line, as you can't close the CurrentDB. It
doesn't cause a problem in current versions of Access, but it might
someday, and since it does absolutely nothing, there's no reason to
do it. The same would be true if you initialized a database variable
using the output from the CurrentDB() function.
Dim stDocName As String

If MsgBox("Make sure your expense report is correct. Once
you
click Yes, you will not be able to change any information. Click
No to go back.", vbYesNo, "Submit Report?") = vbYes Then

Try adding this here:

Me.Refresh
Me.CHECK = True
Me.Dirty = False
stDocName = "Expense Report"
DoCmd.SendObject acReport, stDocName, "snapshot
format" DoCmd.Close
Else
'do nothing
End If
End Sub

Whats happenin is, I am getting the "The data has been changed"
message when I click on this button. I need to click twice on this
button in order to send the email. 1st click: pop up meesage and
2nd click: I can send it. I want to be able to send it un the
first click. What is weird ( and I say weird because I have no
clue what happenin) IF I remove these two lines:
CurrentDb.Synchronize ("path")
CurrentDb.Close
from my code everything works fine. But I MUST synchronize before
I send the e-mail.

Can somebody tell me how to get rid off that "The data has been
changed" message I tried to bypass it trapping the error but it
didnt work.

The problem is that you load a record, then you synchronize (which
may or may not update the record you're viewing) then you make a
change to the record. It seems obvious to me that the synch is
updating the record you're sitting on, so that when you try to save
your edit to the record, you've got a data edit conflict between
your new edit and the edit that came from the synchronization.

The key is to refresh the form *after* the synch, so that it will be
displaying the data that came in from the synch.
 

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

Back
Top