error 2046 - SaveRecord isn't available

L

LisaB

when I try to run the following code from a sub form I get the following
error

RunTime Error 2046 - The commannd or action 'SaveRecord' isn't available
now.

When a certain event happens in this subform I have to be able to save the
record.

Can anyone please help!
 
K

Kevin K. Sullivan

You don't give the code that causes the error. However, I would suggest
that you put:


Me.Dirty = False

within the subform's event. This will save the subform's data.

Chances are, the subform's data is already saved when your current code is
run. You can check the saved state with:

If Me.Dirty = True Then
Me.Dirty = False
Else
'do something else / nothing
End If

The subform's data is automatically saved when the focus moves to the main
form, the subform navagates to a new record, etc.


HTH,

Kevin
 
L

LisaB

Here is the code - I checked the dirty property an it is TRUE when this code
is run
----------------------------------
Private Sub GrantNum_DblClick(Cancel As Integer)


Dim stDocName As String
Dim stLinkCriteria As String


If GrantID = "" Or IsNull(GrantID) Then
GrantID = "temp" & Str(Rnd() * 100)
'Call [frmOrganization].Form.ForceSaveRecord
=============This is where the error is==============
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
==============================================
End If


If Left(GrantID, 4) = "Temp" Then
Me.GrantID = "CSAT" & Me.AutoNum
End If

stDocName = "frmGrants"
PreviousForm = "Organization"


stLinkCriteria = "[GrantID]=" & "'" & Me![GrantID] & "'"

If Me.Contract = "CSAP" Then
msgString = "This is a CSAP Grant"
msgString = msgString + CRLF + CRLF
msgString = msgString + "To Edit info for this grant please use the
CSAP DB Program"
MsgBox msgString, vbOKOnly, "CSAP GRANT"
ElseIf Me.Contract = "CSAT" Then
DoCmd.Minimize
Forms![frmOrganization].Visible = False

DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End Sub
 
K

Kevin K. Sullivan

Can you try replacing the Docmd.DoMenuItem line with Me.Dirty = False?
I am always suspicious that the menu item does not properly account for the
active subform (Perhaps it tries to Save the main form, which is definitely
not Dirty while the subform is Dirty). With a direct reference to Me, you
eliminate the guesswork of the command bar.

HTH,

Kevin

LisaB said:
Here is the code - I checked the dirty property an it is TRUE when this
code
is run
----------------------------------
Private Sub GrantNum_DblClick(Cancel As Integer)


Dim stDocName As String
Dim stLinkCriteria As String


If GrantID = "" Or IsNull(GrantID) Then
GrantID = "temp" & Str(Rnd() * 100)
'Call [frmOrganization].Form.ForceSaveRecord
=============This is where the error is==============
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
==============================================
End If


If Left(GrantID, 4) = "Temp" Then
Me.GrantID = "CSAT" & Me.AutoNum
End If

stDocName = "frmGrants"
PreviousForm = "Organization"


stLinkCriteria = "[GrantID]=" & "'" & Me![GrantID] & "'"

If Me.Contract = "CSAP" Then
msgString = "This is a CSAP Grant"
msgString = msgString + CRLF + CRLF
msgString = msgString + "To Edit info for this grant please use the
CSAP DB Program"
MsgBox msgString, vbOKOnly, "CSAP GRANT"
ElseIf Me.Contract = "CSAT" Then
DoCmd.Minimize
Forms![frmOrganization].Visible = False

DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End Sub


Kevin K. Sullivan said:
You don't give the code that causes the error. However, I would suggest
that you put:


Me.Dirty = False

within the subform's event. This will save the subform's data.

Chances are, the subform's data is already saved when your current code
is
run. You can check the saved state with:

If Me.Dirty = True Then
Me.Dirty = False
Else
'do something else / nothing
End If

The subform's data is automatically saved when the focus moves to the
main
form, the subform navagates to a new record, etc.


HTH,

Kevin
 
L

LisaB

No this does not work

The back end data is in SQL and it seems the problem is SQL does not save
and generate a new autonumber until after the form is closed.

Kevin K. Sullivan said:
Can you try replacing the Docmd.DoMenuItem line with Me.Dirty = False?
I am always suspicious that the menu item does not properly account for the
active subform (Perhaps it tries to Save the main form, which is definitely
not Dirty while the subform is Dirty). With a direct reference to Me, you
eliminate the guesswork of the command bar.

HTH,

Kevin

LisaB said:
Here is the code - I checked the dirty property an it is TRUE when this
code
is run
----------------------------------
Private Sub GrantNum_DblClick(Cancel As Integer)


Dim stDocName As String
Dim stLinkCriteria As String


If GrantID = "" Or IsNull(GrantID) Then
GrantID = "temp" & Str(Rnd() * 100)
'Call [frmOrganization].Form.ForceSaveRecord
=============This is where the error is==============
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
==============================================
End If


If Left(GrantID, 4) = "Temp" Then
Me.GrantID = "CSAT" & Me.AutoNum
End If

stDocName = "frmGrants"
PreviousForm = "Organization"


stLinkCriteria = "[GrantID]=" & "'" & Me![GrantID] & "'"

If Me.Contract = "CSAP" Then
msgString = "This is a CSAP Grant"
msgString = msgString + CRLF + CRLF
msgString = msgString + "To Edit info for this grant please use the
CSAP DB Program"
MsgBox msgString, vbOKOnly, "CSAP GRANT"
ElseIf Me.Contract = "CSAT" Then
DoCmd.Minimize
Forms![frmOrganization].Visible = False

DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End Sub


Kevin K. Sullivan said:
You don't give the code that causes the error. However, I would suggest
that you put:


Me.Dirty = False

within the subform's event. This will save the subform's data.

Chances are, the subform's data is already saved when your current code
is
run. You can check the saved state with:

If Me.Dirty = True Then
Me.Dirty = False
Else
'do something else / nothing
End If

The subform's data is automatically saved when the focus moves to the
main
form, the subform navagates to a new record, etc.


HTH,

Kevin
when I try to run the following code from a sub form I get the
following
error

RunTime Error 2046 - The commannd or action 'SaveRecord' isn't
available
now.

When a certain event happens in this subform I have to be able to
save
the
record.

Can anyone please help!
 

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

Code to force SQL to save a record 2
Error 2046 when using OutputTo 5
acSaveRecord isn't working 1
Deleting a child record 2
Error Code 2046 1
Error 2046 SaveRecord Error 2
SaveRecord command 1
error 2046 2

Top