?
Solved

bound form does not add records

Posted on 2018-02-13
12
High Priority
?
21 Views
Last Modified: 2018-02-13
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?
0
Comment
Question by:João serras-pereira
  • 7
  • 3
  • 2
12 Comments
 

Author Comment

by:João serras-pereira
ID: 42467719
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
 

Author Comment

by:João serras-pereira
ID: 42467724
will be the "Data Entry" flag?


Screen-Shot-2018-02-13-at-16.18.37.png
0
 
LVL 53

Accepted Solution

by:
Gustav Brock earned 3000 total points
ID: 42467729
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:João serras-pereira
ID: 42467733
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
 

Author Comment

by:João serras-pereira
ID: 42467736
or can I use:
DoCmd.GoToRecord , , acNext ?
0
 
LVL 41

Expert Comment

by:PatHartman
ID: 42467747
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
 
LVL 53

Expert Comment

by:Gustav Brock
ID: 42467748
acNewRec it will be.
0
 

Author Closing Comment

by:João serras-pereira
ID: 42467765
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
 

Author Comment

by:João serras-pereira
ID: 42467814
well ... sigh
I need to reopon the case. It's not working again!
0
 
LVL 53

Expert Comment

by:Gustav Brock
ID: 42468151
Perhaps it is time for a relaxing moment doing something else.
0
 

Author Comment

by:João serras-pereira
ID: 42468186
I did!
tomorrow is another day!
0
 
LVL 41

Expert Comment

by:PatHartman
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question