AddNew but I Don't See the New Record

S

SigmaBeta

I use the method AddNew to add a record on a table.The table is displaied in
a ListBox through a simple Query which is its RowSource.
After adding successfully a new record on the table, I would expect to see it
in the ListBox, but I don't.
I can see the new record only when I close the form and open it again.

The code includes also a Move Last at the end and a Me.Refresh before
exiting the Sub Routine.

I cannot use the command Requery because the ListBox is opened dynamically by
another form containing its RowSource.

I have tried to set the ListBox RowSource = "" and to query again without any
result.

How can I have displaied any new record immediately after adding it?

Thank You.
 
D

Douglas J. Steele

Not sure I understand your comment "I cannot use the command Requery because
the ListBox is opened dynamically by another form containing its
RowSource.". So what? As long as it has a RowSource assigned to it, you
should be able to requery it. Have you tried issuing a Requery on the list
box? If so, what happened?
 
S

SigmaBeta via AccessMonster.com

Douglas said:
Not sure I understand your comment "I cannot use the command Requery because
the ListBox is opened dynamically by another form containing its
RowSource.". So what? As long as it has a RowSource assigned to it, you
should be able to requery it. Have you tried issuing a Requery on the list
box? If so, what happened?
I use the method AddNew to add a record on a table.The table is displaied
in
[quoted text clipped - 18 lines]
Thank You.
Yes I tried.
I even tried to annull the current rowsource with the instructions:

Me.ListBox1.Rowsource = ""
Me.ListBox1.Rowsource ="SELECT * ..."
Me.Refresh

but I continue not to see the new record.
The new record appears in the ListBox only after adding another new one, but
in this cas I don't see this last added.
Do you think it might be because the DB is not in the same *.mdb containing
forms and modules?
Thank You.
 
D

Douglas J. Steele

AccessVandal via AccessMonster.com said:
Try.....

Me.ListBox1.Requery

That's the correct syntax, but given that the RowSource is being reset, it
really shouldn't be necessary.\

However, it's certainly worth a try.
 
D

Douglas J. Steele

SigmaBeta via AccessMonster.com said:
Yes I tried.
The new record appears in the ListBox only after adding another new one,
but
in this cas I don't see this last added.
Do you think it might be because the DB is not in the same *.mdb
containing
forms and modules?

You mean you've got a split application? That's the way all applications
should be. It shouldn't be the cause of the problem.
 
S

SigmaBeta via AccessMonster.com

Douglas said:
[quoted text clipped - 10 lines]
containing
forms and modules?

You mean you've got a split application? That's the way all applications
should be. It shouldn't be the cause of the problem.
I have found a sort of solution.
At the end of the AddNew instruction I put a MsgBox that put an useless
question, just to waste time.
When the MsgBox closes, the new record appears.
I know that it is a "dirty" way of processing but it works!
What do yoi think?
 
A

AccessVandal via AccessMonster.com

You only showed us a part of your code. So we can’t even suggest.

Examples, if you open a recordset then requery the listbox, the new record
might not appear in the listbox. You must close the recordset first before
you requery the listbox.
 
S

SigmaBeta via AccessMonster.com

Definitely this is an example of code.
"lstFirm0a" is the listbox that doesn't show the new record.
It's record source is definited dynamically in the code of another form
opening the current one.

If I write Debug.Print !IDRule or better I insert an useless MsgBox with a
question like "Is it ok?" I will see the new record.
It gives me the impression that the application needs a sort of relaxing time
to display the new record.

Dim dbs as DataBase
Dim rst4 as recordset

Set rst4 = dbs.OpenRecordset("Relation")
With rst4
.AddNew
!IDFirm = Me.cmbIDFirm0a
!IDPerson = Me.txtIDPersonal0a
!IDRule = Me.cmbIDRule0a
!Start = Date
.Update
.MoveLast
Debug.Print !IDRule
.Close
End With

Me.lstFirm0a.Requery
Me.Refresh
 
A

AccessVandal via AccessMonster.com

Although the code is not complete, it doesn’t tell us what happened like is
there an error message from the VB editor?

Here’s the code that’s working for me. Take Note of the comments in the code.

Make sure that you have referances set correctly, Microsoft DAO 3.6 Object
Library.

Dim dbs as DAO.DataBase
Dim rst4 as DAO.Recordset

Set dbs = CurrentDB ‘how come no error?

Set rst4 = dbs.OpenRecordset("Relation") ‘Relation a table?
With rst4
.AddNew
!IDFirm = Me.cmbIDFirm0a
!IDPerson = Me.txtIDPersonal0a
!IDRule = Me.cmbIDRule0a
!Start = Date ‘please rename “Start†as it is a reserved word
.Update
.MoveLast
.Close
End With

Me.lstFirm0a.Requery
‘Me.Refresh ‘don’t need to refresh the form unless……
‘Set rst4 = Nothing ‘ some in your code?

Definitely this is an example of code.
"lstFirm0a" is the listbox that doesn't show the new record.
It's record source is definited dynamically in the code of another form
opening the current one.

If I write Debug.Print !IDRule or better I insert an useless MsgBox with a
question like "Is it ok?" I will see the new record.
It gives me the impression that the application needs a sort of relaxing time
to display the new record.

Dim dbs as DataBase
Dim rst4 as recordset

Set rst4 = dbs.OpenRecordset("Relation")
With rst4
.AddNew
!IDFirm = Me.cmbIDFirm0a
!IDPerson = Me.txtIDPersonal0a
!IDRule = Me.cmbIDRule0a
!Start = Date
.Update
.MoveLast
Debug.Print !IDRule
.Close
End With

Me.lstFirm0a.Requery
Me.Refresh
You only showed us a part of your code. So we can’t even suggest.
[quoted text clipped - 8 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top