Form Not Saving New Record Info

mvanella

Registered User.
Local time
Today, 03:10
Joined
Nov 15, 2012
Messages
29
I have a popup input form that I am using to accomplish 2 separate tasks. When viewing an RMA, a user can input new or edit an existing labor entry. There's a button on the RMA form that allows them to enter new, and there's an edit hyperlink with a click event for each entry that allows the editing of that record only. If the user clicks either of these one form is loaded as a pop up with either the record being edited or an essentially blank form with a new ID for the associated table. The edit functionality works great, no problems there. When a new entry is created, it doesn't actually create an entry in the table, so something somewhere is not being saved. Here's my code:

For the New Entry button:
Code:
Private Sub cmdNewLaborEntry_Click()
    'Set to openargs to NEW, and open form
    Dim strOpenArgs As String
    strOpenArgs = "NEW|" & txtRMA.Value
        
    DoCmd.OpenForm "frmChangeLaborEntry", acNormal, , , acFormAdd, , strOpenArgs
End Sub

For the Edit Entry button
Code:
Private Sub txtEditLink_Click()
    'Grab the ID value, Set to openargs, and open form
    DoCmd.OpenForm "frmChangeLaborEntry", acNormal, OpenArgs:=Me.txtID.Value
End Sub

And here's the on_open event for the popup form
Code:
Private Sub Form_Open(Cancel As Integer)
    'Check for openargs
    If IsNull(Me.OpenArgs) Then
        MsgBox "Openargs is null. No data loaded. Now closing form."
        DoCmd.Close acForm, "frmChangeLaborEntry", acSaveNo
        End
    End If
    
    Dim strSQLGetID As String
    Dim strOpenArgs As String
    strOpenArgs = Me.OpenArgs
    
    'If OpenArgs is numeric:
    If IsNumeric(strOpenArgs) Then
        Dim intRecordID As Integer
        intRecordID = strOpenArgs
        strSQLGetID = "SELECT * FROM tblRMALabor WHERE ID = " & intRecordID & ";"
        Me.RecordSource = strSQLGetID
    'If OpenArgs begins with "NEW|"
    ElseIf Left(strOpenArgs, 4) = "NEW|" Then
        strSQLGetID = "SELECT * FROM tblRMALabor;"
        Me.RecordSource = strSQLGetID
        txtRMA.Value = Mid(strOpenArgs, 5, Len(strOpenArgs))
    'Does not fit above criteria
    Else
        MsgBox "Openargs is not formatted correctly." & vbCrLf & _
            "Me.OpenArgs read in as: " & Me.OpenArgs & vbCrLf & _
            "Ending macro and closing form."
        DoCmd.Close acForm, "frmChangeLaborEntry", acSaveNo
    End If
End Sub
 
Check the popups record source, it may be a non-updatable recordset.
 
Check the AllowAdditions for the form.
 
Recordsource is "tblRMALabor"
Recordset Type: Dynaset
Data Entry: Yes
Allow Additions: Yes
Allow Deletions: No
Allow Edits: Yes
Allow Filters: Yes
Record Locks: No Locks
 
Looks ok, what when you open the form directly?
 
It opens the form with the ID textbox as "(New)" and the rest of the textboxes are blank. I can put in information, but it wont commit the changes.
 
It opens the form with the ID textbox as "(New)" and the rest of the textboxes are blank. I can put in information, but it wont commit the changes.
What du you mean with "(New)"?
I would have expected ID textbox was blank too, (or with a number).
For me it looks like an unbound form, (no RecordSource).
 
JHB, the box has a text value of "(New)". The form's recordsource is that of tblRMALabor.

I use the form for two different actions on records from the same table.

The current click event in question launches the form to a new record, for data entry.

Code:
Private Sub cmdNewLaborEntry_Click()
    'Open the ChangeLaborEntry form to a new entry
    DoCmd.OpenForm "frmChangeLaborEntry", acNormal, , , acFormAdd, , OpenArgs:=Me.txtRMA.Value
End Sub

A second, a link field on a datasheet, launches the form to edit the specified entry, by ID. This edit event works great, and the changes are committed.

Code:
Private Sub txtEditLink_Click()
    'Grab the ID value, Set to openargs, and open form
    DoCmd.OpenForm "frmChangeLaborEntry", acNormal, , "ID = " & Me.txtID.Value, acFormEdit, acDialog
End Sub

On the form itself, the Before_Update Event asks the user to confirm changes:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If MsgBox("Changes have been made to this record." _
    & vbCrLf & vbCrLf & "Would you like to save these changes?", _
    vbYesNo, "Confirm Changes to Record") = vbYes Then
        DoCmd.Save
    Else
        DoCmd.RunCommand acCmdUndo
    End If
End Sub

I am not changing any properties in On_Load or On_Open other than whether an ID box and the RMA box are locked for editing or not
Code:
Private Sub Form_Load()
    With Me
        .txtID.Locked = True
        .txtRMA.Locked = True
    End With
    
    If Not IsNull(Me.OpenArgs) Then
        Me.txtRMA.Value = Me.OpenArgs
    End If
End Sub

Do you see anything in here that would cause the dual use of this form to conflict with saving a new record?
 
It looks all ok, but if you not can save new records, then ....!
Are you using af Front-/Backend setup?
If yes, do you have the premission to add new records to the table?
Open the table and try to add a new record.
 
Yes the tables are in the backend and linked to this front end app. I have full permissions for the table and can add new records via the table itself. I can make a demo version with dummy data and attach it if that helps, maybe there's something going on somewhere else. The tables in the backend are Access 2010 Web Compatible tables so they have more restrictions as to what kinds of data types and relationships they can have but I've seen no functional difference in adding/modifying/deleting data since I've been using them. The front end is all VBA driven, so its an offline application.
 
Here's a front and back end with (I believe) all proprietary information removed and a few dummy entries. Full functionality will only work in Access 2010, and you will also have to re-link the tables when you extract it. The frmWhiteboardLAN is the main navigation form, if you click on the Repairs Tab you get to the main form in question (frmRMAReport) and the subform on that form that holds the hours is frmAssociatedHours. The button "New Labor Entry" is the culprit and it launches frmChangeLaborEntry.
 

Attachments

Sorry mvanella, I don't have 2010 version here, is it possible for you to convert it to 2000 version.
I would like to see what it is there causes the problem, then by now I'm almost running out of ideas.
 
Access won't let me convert it to 2000 because it uses so many of the newer features. Even trashing the navigation form won't satisfy the requirements.

"These features include attachments, multi-valued fields, offline data, data macros, calculated columns, links to unsupported external files, newer sort orders, newer encryption types, and navigation controls"
The only things above that I can think that match those restraints are the calculated columns in some of my queries (not in the tables) and I have a form which makes a hyperlink link to a local file in a textbox, but again that data isn't stored in a table, it's dynamically created on the form/report after some code runs.
 
Ok - hope you'll get the form to save new entries.
 
Bumping to see if anyone with a Access 2010 can test out the forms for me. Still wracking my brain on this one.
 
mvanella, if I were you, I would start with a brand new form with only the most needed fields (controls) for adding a new record.
If it works, then I'll start adding more and more from the form that not works, (one thing a time, controls, code, etc.) until you find the control, code or what ever, which not allow you to add a record.
 

Users who are viewing this thread

Back
Top Bottom