Code help

G

Guest

I have this piece of code below and when I run it it says that SaveRecord is
not available. Does anyone have a clue why.


Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

save = True

Dim sessionDate As Date

Dim qdfDone As DAO.QueryDef
Dim qdfStudyIdSSN As DAO.QueryDef
Dim qdfNextDate As DAO.QueryDef
Dim qdfRemindDate As DAO.QueryDef

'If Check1 = "Yes" Then
'Since we are adding to two tables, lets make it a transaction
DBEngine.BeginTrans

Set qdfDone = CurrentDb.QueryDefs("QueryAddDoneSession")
qdfDone.Parameters("newId") = InterviewID
qdfDone.Parameters("newVisit") = 1
qdfDone.Execute


Set qdfNextDate = CurrentDb.QueryDefs("QueryAddStatusNextDate")
qdfNextDate.Parameters("newId") = InterviewID
qdfNextDate.Parameters("newVisit") = 2 'schedule next interview
qdfNextDate.Parameters("newInterviewDate") = sessionDate + 350
qdfNextDate.Execute

qdfNextDate.Close

Set qdfRemindDate =
CurrentDb.QueryDefs("QueryAddStatusReminderDate")
qdfRemindDate.Parameters("newId") = InterviewID
qdfRemindDate.Parameters("newVisit") = 1
qdfRemindDate.Parameters("newCallDate") = sessionDate + 290
qdfRemindDate.Execute

qdfRemindDate.Close



DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
save = False
Call InterviewSession.CloseSession
'End If

Form.Requery

Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub
 
R

Rick Brandt

pokdbz said:
I have this piece of code below and when I run it it says that SaveRecord is
not available. Does anyone have a clue why.


Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

save = True

Dim sessionDate As Date

Dim qdfDone As DAO.QueryDef
Dim qdfStudyIdSSN As DAO.QueryDef
Dim qdfNextDate As DAO.QueryDef
Dim qdfRemindDate As DAO.QueryDef

'If Check1 = "Yes" Then
'Since we are adding to two tables, lets make it a transaction
DBEngine.BeginTrans

Set qdfDone = CurrentDb.QueryDefs("QueryAddDoneSession")
qdfDone.Parameters("newId") = InterviewID
qdfDone.Parameters("newVisit") = 1
qdfDone.Execute


Set qdfNextDate = CurrentDb.QueryDefs("QueryAddStatusNextDate")
qdfNextDate.Parameters("newId") = InterviewID
qdfNextDate.Parameters("newVisit") = 2 'schedule next interview
qdfNextDate.Parameters("newInterviewDate") = sessionDate + 350
qdfNextDate.Execute

qdfNextDate.Close

Set qdfRemindDate =
CurrentDb.QueryDefs("QueryAddStatusReminderDate")
qdfRemindDate.Parameters("newId") = InterviewID
qdfRemindDate.Parameters("newVisit") = 1
qdfRemindDate.Parameters("newCallDate") = sessionDate + 290
qdfRemindDate.Execute

qdfRemindDate.Close



DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
save = False
Call InterviewSession.CloseSession
'End If

Form.Requery

Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub

If the form that this code is running behind hasn't been "dirtied" then
there is nothing to save. Whatever changes you are processing with your
queries have nothing to do with the record currently on the form.
 
R

Rick Brandt

You are also never committing your transaction so your queries are doing
nothing. Whenever you have a BeginTransaction somewhere later you need
either a Rollback or a Commit.
 
G

Guest

Thanks for the help.
What does dirty do anyway I am confused about this term and what it does?

Also what is the difference between commit and rollback
 
R

Rick Brandt

pokdbz said:
Thanks for the help.
What does dirty do anyway I am confused about this term and what it does?

The record (or form) is dirtied as soon as an edit is initiated, but not
yet saved. So the Dirty property is true when a record is in a state of
flux. It has been entered or edited, but not yet saved. After the record
is saved the Dirty property is false. By coincidence setting the Dirty
property to False forces the record to be saved.
Also what is the difference between commit and rollback

Commit means "Save everything I did since I started the transaction" Which
is the equivalent of saving the record(s).

Rollback means "Never mind, drop all the changes since I started the
transaction" which is the equivalent of pressing <Escape> to cancel any
changes.
 
G

Guest

Ok i get Dirty now. Also the rollback and commit i get.

How do I go about using the dirty statement in my program to make it save
and chagne the information that needs updated or saved.
Thanks
 
R

Rick Brandt

pokdbz said:
Ok i get Dirty now. Also the rollback and commit i get.

How do I go about using the dirty statement in my program to make it save
and chagne the information that needs updated or saved.
Thanks

Your code was making data changes by executing queries inside a
transaction. You need a line with a Commit statement (don't know the exact
statement off-hand), and those changes will be saved. The Requery that you
have in your code will take care of the form as that would also save any
changes that the form might have still outstanding.
 
G

Guest

I added the commit statement in as shown below. But it does not do anything.
When I step through the debugger it says that everything this null. What
about this dirty statement. What do I have to do with that, would that cause
this to be null for the queries?
Thanks


Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

save = True

Dim sessionDate As Date

Dim qdfDone As DAO.QueryDef
Dim qdfStudyIdSSN As DAO.QueryDef
Dim qdfNextDate As DAO.QueryDef
Dim qdfRemindDate As DAO.QueryDef

If Check1 = "Yes" Then

DBEngine.BeginTrans

Set qdfDone = CurrentDb.QueryDefs("QueryAddDoneSession")
qdfDone.Parameters("newId") = InterviewID
qdfDone.Parameters("newVisit") = 1
qdfDone.Execute

DBEngine.CommitTrans

Set qdfNextDate = CurrentDb.QueryDefs("QueryAddStatusNextDate")
qdfNextDate.Parameters("newId") = InterviewID
qdfNextDate.Parameters("newVisit") = 2 'schedule next interview
qdfNextDate.Parameters("newInterviewDate") = sessionDate + 350
qdfNextDate.Execute

qdfNextDate.Close

Set qdfRemindDate =
CurrentDb.QueryDefs("QueryAddStatusReminderDate")
qdfRemindDate.Parameters("newId") = InterviewID
qdfRemindDate.Parameters("newVisit") = 1
qdfRemindDate.Parameters("newCallDate") = sessionDate + 290
qdfRemindDate.Execute

qdfRemindDate.Close



DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
save = False
Call InterviewSession.CloseSession
End If

Form.Requery

Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub
 
G

Guest

Also the code is in a subform called Subform4MonthStatus. Which has the save
button on it.

This subform is on the main form called FormInterviewCalendar2 which has the
InterviewId on it.

Do you think this might be part of the problem with the dirty. Im not
really sure I just thought that I would let you know if this helps.
Thanks
 

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

Similar Threads


Top