dtbaker
asked on
DoCmd.RunCommand acCmdSaveRecord returns Invalid use of Null
Hello,
Any help would be appreciated.
Problem: I keep getting an error message "Invalid use of Null" returned on DoCmd.RunCommand acCmdSaveRecord. I want to save the record, then immediately return a field to use. I'm trying to return [Forms]![CreateSCRSub]![SC R ID] which is the primary key and auto-incremented.
Using: Access 2000 & XP database front-end with a SQL 7 server back-end. This error happens almost everytime on AccessXP a sporadically on the Access 2000 front-end.
Some example code:
____
Private Sub SaveSCR()
On Error GoTo Err_SaveSCR
Dim dbsMSCR As Database
Dim rsNew As Recordset
Dim rsDependent As Recordset
Dim rsTempRecord As Recordset
Dim rsChangeRequest As Recordset
'Copy the Form stuff to the record
DoCmd.OpenForm "CreateSCRSub", acNormal, , , acFormAdd, acHidden
[Forms]![CreateSCRSub]!Nam e = txtName
[Forms]![CreateSCRSub]!Sof tware = Software
[Forms]![CreateSCRSub]!Des cription = Description
[Forms]![CreateSCRSub]!Pri ority = Priority
[Forms]![CreateSCRSub]!Ori ginator = Originator
'Save Record to Get the Number
DoCmd.RunCommand acCmdSaveRecord
mySCRID = [Forms]![CreateSCRSub]![SC R ID]
'Set to Curent DB
Set dbsMSCR = CurrentDb
'Open the BugNumbers Table
Set rsNew = dbsMSCR.OpenRecordset("Bug Numbers", dbOpenDynaset, dbSeeChanges)
'Open the Dependencies Table
Set rsDependent = dbsMSCR.OpenRecordset("Dep endancy List", dbOpenDynaset, dbSeeChanges)
'Open the TempBufDepTable
Set rsTempRecord = dbsMSCR.OpenRecordset(strM yUniqueNam e, dbOpenTable, dbReadOnly)
If Not (rsTempRecord.EOF) Then
rsTempRecord.MoveFirst
While Not (rsTempRecord.EOF)
If (rsTempRecord("Dependency" )) Then
rsDependent.AddNew
rsDependent("Source SCR ID") = mySCRID
rsDependent("Depends Upn SCR ID") = rsTempRecord("Dependency")
rsDependent.Update
rsDependent.MoveNext
End If
rsTempRecord.MoveNext
Wend
End If
'Close RecordSets
rsTempRecord.Close
rsNew.Close
'Close Forms
DoCmd.Close acForm, "UserCreateSCRSub"
DoCmd.Close acForm, "CreateSCRSub", acSaveYes
'Mark State as Closed
Set rsChangeRequest = dbsMSCR.OpenRecordset("Cha nge Requests", dbOpenDynaset, dbSeeChanges)
rsChangeRequest.FindFirst "[SCR ID] = " & mySCRID
rsChangeRequest.Edit
rsChangeRequest("State") = enumCreated
rsChangeRequest.Update
rsChangeRequest.Close
Set dbsMSCR = Nothing
'Error Handeling
Exit_SaveSCR:
Exit Sub
Err_SaveSCR:
MsgBox Err.Description
Resume Exit_SaveSCR
End Sub
_____________
Thanks
Any help would be appreciated.
Problem: I keep getting an error message "Invalid use of Null" returned on DoCmd.RunCommand acCmdSaveRecord. I want to save the record, then immediately return a field to use. I'm trying to return [Forms]![CreateSCRSub]![SC
Using: Access 2000 & XP database front-end with a SQL 7 server back-end. This error happens almost everytime on AccessXP a sporadically on the Access 2000 front-end.
Some example code:
____
Private Sub SaveSCR()
On Error GoTo Err_SaveSCR
Dim dbsMSCR As Database
Dim rsNew As Recordset
Dim rsDependent As Recordset
Dim rsTempRecord As Recordset
Dim rsChangeRequest As Recordset
'Copy the Form stuff to the record
DoCmd.OpenForm "CreateSCRSub", acNormal, , , acFormAdd, acHidden
[Forms]![CreateSCRSub]!Nam
[Forms]![CreateSCRSub]!Sof
[Forms]![CreateSCRSub]!Des
[Forms]![CreateSCRSub]!Pri
[Forms]![CreateSCRSub]!Ori
'Save Record to Get the Number
DoCmd.RunCommand acCmdSaveRecord
mySCRID = [Forms]![CreateSCRSub]![SC
'Set to Curent DB
Set dbsMSCR = CurrentDb
'Open the BugNumbers Table
Set rsNew = dbsMSCR.OpenRecordset("Bug
'Open the Dependencies Table
Set rsDependent = dbsMSCR.OpenRecordset("Dep
'Open the TempBufDepTable
Set rsTempRecord = dbsMSCR.OpenRecordset(strM
If Not (rsTempRecord.EOF) Then
rsTempRecord.MoveFirst
While Not (rsTempRecord.EOF)
If (rsTempRecord("Dependency"
rsDependent.AddNew
rsDependent("Source SCR ID") = mySCRID
rsDependent("Depends Upn SCR ID") = rsTempRecord("Dependency")
rsDependent.Update
rsDependent.MoveNext
End If
rsTempRecord.MoveNext
Wend
End If
'Close RecordSets
rsTempRecord.Close
rsNew.Close
'Close Forms
DoCmd.Close acForm, "UserCreateSCRSub"
DoCmd.Close acForm, "CreateSCRSub", acSaveYes
'Mark State as Closed
Set rsChangeRequest = dbsMSCR.OpenRecordset("Cha
rsChangeRequest.FindFirst "[SCR ID] = " & mySCRID
rsChangeRequest.Edit
rsChangeRequest("State") = enumCreated
rsChangeRequest.Update
rsChangeRequest.Close
Set dbsMSCR = Nothing
'Error Handeling
Exit_SaveSCR:
Exit Sub
Err_SaveSCR:
MsgBox Err.Description
Resume Exit_SaveSCR
End Sub
_____________
Thanks
please shane you are so intelligent i need your help
ASKER
Sorry Shanesuebsahakarn,
Gives an endless loop. :(
Just the Me.Refresh doesn't work either.
Gives an endless loop. :(
Just the Me.Refresh doesn't work either.
Very odd, it would seem that the data isn't being committed. I don't suppose replacing the doCmd with:
Me.Dirty = False
makes a difference ?
Me.Dirty = False
makes a difference ?
ASKER
Sorry Shanesuebsahakarn,
Gives an endless loop. :(
Just the Me.Refresh doesn't work either.
Gives an endless loop. :(
Just the Me.Refresh doesn't work either.
ASKER
I tried Me.Dirty = False before to save the record and I get a totally different error in both Access xp and 2000.
Got this error message "You entered an expression that has an invalid reference to the property Dirty."
Got this error message "You entered an expression that has an invalid reference to the property Dirty."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Shanesuesahakarn,
Using the fully qualified path worked. Thanks for you quick and simple solutions.
Using the fully qualified path worked. Thanks for you quick and simple solutions.
NP, glad I could help!
DoCmd.RunCommand acCmdSaveRecord
While IsNull([Forms]![CreateSCRS
Me.Refresh
Wend
The Me.Refresh line may or may not be needed, but try it out and see if it helps.