bound form does not add records

On my app I have  a form that pops up, aks for some data, computes, and should insert a new record in the DB. One of the things it does is to compute a new key, and the key is alright.
The situation is that the form is bound to a table, and on the properties is does allow only for "add records" (no Edits and no Deleets).
But in result is only editing the last record and never adding a new record,
Can anyone help?
João serras-pereiraAsked:
Who is Participating?
 
Gustav BrockCIOCommented:
Nowhere seem you to goto a new record or calling rs.AddNew.
Without that, you will be editing the current record (which you can't).
0
 
João serras-pereiraAuthor Commented:
a post scrimptum. The full code is below:


Private Sub btn_sairNovoExame_Click()

On Error GoTo errorTrap

    Call logMe("btn_sairNovoExame_Click", "start")
    If IsNull(Me.frm_MotivoExame) Then
        MsgBox "Motivo de Exame não preenchido"
    End If
    If IsNull(Me.frm_dataExame) Then
        MsgBox "Data de Exame não preenchida"
    End If
    Me.frm_idExame = Forms![_intData].frm_exameRecCount
    Forms![_intData].frm_exameSalvo = True
    Forms("frmPaciente").frmExameLista.Requery

    If Me.Dirty = True Then
        Me.Dirty = False
    End If
    Call logMe("btn_sairNovoExame_Click", "end")
    DoCmd.Close acForm, "frmExameNovo"
    Exit Sub
    
errorTrap:
    MsgBox "[btn_sairNovoExame_Click]." & "[" & Err.Number & "].[" & Err.Description & "]"
    Call logMe("btn_sairNovoExame_Click", "errorTrap:" & "[btn_sairNovoExame_Click]." & "[" & Err.Number & "].[" & Err.Description & "]")
    Resume Next
    
End Sub

Open in new window

0
 
João serras-pereiraAuthor Commented:
will be the "Data Entry" flag?


Screen-Shot-2018-02-13-at-16.18.37.png
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
João serras-pereiraAuthor Commented:
ha! Ok I thought that when the form is bound I should not use rs.addnew
I am pasting it back (the form was unboud before...)
0
 
João serras-pereiraAuthor Commented:
or can I use:
DoCmd.GoToRecord , , acNext ?
0
 
PatHartmanCommented:
When you use the OpenForm method, one of the options is to open in Add mode.  If you do that, the form will open to a new record.  NO CODE required.  No need to permanently set the Data Entry property to yes.

PS - That isn't even close to being the full code.
1. We don't know what form is running the code
2. You didn't post the LogMe function.
3. You don't seem to have any code in the form's BeforeUpdate event so you are not properly validating the new record.
0
 
Gustav BrockCIOCommented:
acNewRec it will be.
0
 
João serras-pereiraAuthor Commented:
Hi.
It runs (well close as now it always create a blank record :()

and Patwas right - it was not the full code, but (currently) almost all. I have just a bit of preparing code on the "on load" event" but it is unrelated - well it was. Now I have  the DoCmd.GoToRecord , , acNewRec  there and that's why I always getting a blank record.
... I'll find a way out...
0
 
João serras-pereiraAuthor Commented:
well ... sigh
I need to reopon the case. It's not working again!
0
 
Gustav BrockCIOCommented:
Perhaps it is time for a relaxing moment doing something else.
0
 
João serras-pereiraAuthor Commented:
I did!
tomorrow is another day!
0
 
PatHartmanCommented:
Now I have  the DoCmd.GoToRecord , , acNewRec  there and that's why I always getting a blank record.
... I'll find a way out...
Change the way you are opening the form and you won't have to force it to go to a new record.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.