Missing newly added record from continuous form

MilaK

Registered User.
Local time
Today, 12:35
Joined
Feb 9, 2015
Messages
285
Hello,

I use the following code to add a new record line and populate it with values.

Code:
Dim str_sampleid As String
If Me.cmb_samples.Column(0) = "(All)" Then
MsgBox "Select sample to add new record"
Exit Sub
End If
 Application.Echo False
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
'populate fields with data

str_sampleid = Me.cmb_samples.Column(3) & "_" & Me.cmb_samples.Column(0)
Debug.Print str_sampleid
Me.sample_id = str_sampleid
Me.sample_name = Me.cmb_samples.Column(0)
Me.tumor_type = Me.cmb_samples.Column(1)

Me.AllowAdditions = False
 Application.Echo True
 
 DoCmd.RunCommand acCmdSaveRecord
The problem is, I can’t find this new record again on the form after I filter the form. Even after I remove the filter to show all records, this new record doesn’t show up on the form.
However, when I open the table that serves as the record source I can see the record is in the table.

Could someone suggest how to fix this problem?

Thanks
 
is your form "data entry" set to "true"@

a data entry form just shows items entered in the current entry session.
set it to false, to see existing items.
 
Hi Dave,

"data entry" was set to No. I set it to Yes but the same problem persists.

Thanks
 
did you try to requery your form recordsource?
 
If you click the Refresh All icon, does that show the new record?
 
If you click the Refresh All icon, does that show the new record?

Refreshing didn't help.

The form connected to the table is a sub-form. Also, when I add a new record the form is filtered... not sure if it's causing the problem.

When I open the table, I see the added record but it's not visible on the form.
 
What if you close the form and open it again, does it show up then?
 
You need to Requery the involved Form after the line

DoCmd.RunCommand acCmdSaveRecord

Refresh reflects changes made to the Records in the current RecordSet. It should be noted that Refresh doesn't reflect Records that have been Added or Deleted since the RecordSet was last Requeried.

Also, Records that no longer satisfy the Criteria of the Query or Filter will not be excluded.

Requery rather than Refresh, is usually the way to go. People frequently try to avoid it because Focus returns to the first Record in the Form. To Requery a Record Source and then return to the Current Record, where [UniqueID] is a Field unique to only one Record:

Where [UniqueID] is Text

Code:
 Private Sub SaveRequeryReturn_Click()

Dim UF_Rec As String
   
   UF_Rec = Me!UniqueID
   Me.Requery
   Me.Recordset.FindFirst "[UniqueID] = '" & UF_Rec & "'"

End Sub
Where [UniqueID] is Numeric

Code:
 Private Sub SaveRequeryReturn_Click()

Dim UF_Rec As Integer
   
   UF_Rec = Me!UniqueID
   Me.Requery
   Me.Recordset.FindFirst "[UniqueID] = " & UF_Rec

End Sub

Linq ;0)>
 
The problem was that I wasn't assigning a value to one of the primary key fields, therefore, that record wasn't visible on the form.

Thank you very much to JHB for helping to diagnose the issue.
 

Users who are viewing this thread

Back
Top Bottom