Link to home
Start Free TrialLog in
Avatar of João serras-pereira
João serras-pereiraFlag for Portugal

asked on

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?
Avatar of João serras-pereira
João serras-pereira
Flag of Portugal image

ASKER

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

will be the "Data Entry" flag?


User generated image
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...)
or can I use:
DoCmd.GoToRecord , , acNext ?
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.
acNewRec it will be.
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...
well ... sigh
I need to reopon the case. It's not working again!
Perhaps it is time for a relaxing moment doing something else.
I did!
tomorrow is another day!
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.