R
Rob
Hi all,
I currently have a form that I have set for DataEntry to allow a user
to create a new record. I have disabled the navigation buttons to
allow a custom 'Save' routine to be developed. I added a command
button to the form to allow the record to be saved using the wizard.
The wizard uses the DoCmd.DoMenuItem method, however I am concerned
that this will not be valid when I change menu bars later.
Consequently, I developed some code to run a Db.Execute command (see
below) to add the record manually.
--------------------------------
For Each Ctrl In Me.Controls
If TryGetControlValue(Ctrl) = True Then 'Check for
editable controls
If IsNull(Len(Ctrl.Value)) Then
boolNull = True
End If
strCol = strCol & Ctrl.ControlSource & ","
strVal = strVal & "'" & Ctrl.Value & "',"
End If
Next Ctrl
' Strip the additional comma from the string and add brackets
strCol = " (" & Left(strCol, Len(strCol) - 1) & ")"
strVal = "(" & Left(strVal, Len(strVal) - 1) & ")"
If boolNull = True Then
MsgBox "Data error. Please try again", vbInformation, "Data
error"
Else
strSQL = "INSERT INTO " & Me.RecordSource & strCol & " VALUES
" & strVal
Debug.Print strSQL
db.Execute strSQL
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
End If
----------------------------------------------
This code seems to work well until I attempt to close the form. In
this case I get a "Duplicate record" error which I am sure is related
to the DataEntry property.I have experimented with Me.Dirty however
this does not work either.
Any help anybody could provide would be greatly appreciated,
Cheerss
I currently have a form that I have set for DataEntry to allow a user
to create a new record. I have disabled the navigation buttons to
allow a custom 'Save' routine to be developed. I added a command
button to the form to allow the record to be saved using the wizard.
The wizard uses the DoCmd.DoMenuItem method, however I am concerned
that this will not be valid when I change menu bars later.
Consequently, I developed some code to run a Db.Execute command (see
below) to add the record manually.
--------------------------------
For Each Ctrl In Me.Controls
If TryGetControlValue(Ctrl) = True Then 'Check for
editable controls
If IsNull(Len(Ctrl.Value)) Then
boolNull = True
End If
strCol = strCol & Ctrl.ControlSource & ","
strVal = strVal & "'" & Ctrl.Value & "',"
End If
Next Ctrl
' Strip the additional comma from the string and add brackets
strCol = " (" & Left(strCol, Len(strCol) - 1) & ")"
strVal = "(" & Left(strVal, Len(strVal) - 1) & ")"
If boolNull = True Then
MsgBox "Data error. Please try again", vbInformation, "Data
error"
Else
strSQL = "INSERT INTO " & Me.RecordSource & strCol & " VALUES
" & strVal
Debug.Print strSQL
db.Execute strSQL
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
End If
----------------------------------------------
This code seems to work well until I attempt to close the form. In
this case I get a "Duplicate record" error which I am sure is related
to the DataEntry property.I have experimented with Me.Dirty however
this does not work either.
Any help anybody could provide would be greatly appreciated,
Cheerss