Can't see data just saved to table on my form

R

ramblinwreck

I use a form to enter/update info to two different tables. I have a command
button that allows me to create a new record and code executed creates the
new record.

When I go to the table, I can see the new information is there.

I inserted a requery statement in my code and after executing the form
updates to show a new number of records and if I move through the records I
can see the one I just created.

What I can't figure out is how to get the form to display the information
from the record I just created. After I requery, the form goes back to the
first record.

All I want is for the controls in the form to display the values from the
record I just created. Like I said, I can do this by moving through the
database but I have to imagine there must be a way to do this without my
intervention.

please help.

thanks.
 
R

Rick Brandt

ramblinwreck said:
I use a form to enter/update info to two different tables. I have a
command button that allows me to create a new record and code
executed creates the new record.

When I go to the table, I can see the new information is there.

I inserted a requery statement in my code and after executing the form
updates to show a new number of records and if I move through the
records I can see the one I just created.

What I can't figure out is how to get the form to display the
information from the record I just created. After I requery, the
form goes back to the first record.

All I want is for the controls in the form to display the values from
the record I just created. Like I said, I can do this by moving
through the database but I have to imagine there must be a way to do
this without my intervention.

please help.

thanks.

Why are you issuing a Requery? That is what makes the form go back to the first
record.
 
R

ramblinwreck

The reason for the requery was I otherwise could not see the record I just
saved on the current form unless I closed the form and reopened it.
 
R

Rick Brandt

ramblinwreck said:
The reason for the requery was I otherwise could not see the record I
just saved on the current form unless I closed the form and reopened
it.

If you are using a bound form then you are looking at the record as you are
entering it. What more do you need to "see"?

Anyway; use Me.Dirty = False or DoCmd.RunCommand acCmdSaveRecord instead of
Requery.
 
M

missinglinq via AccessMonster.com

Where the unique field name in your underlying table is CustomerName and the
control on your form holding this field is CustNam

RecID = Me!CustNam
Me.Requery
Me.Recordset.FindFirst "[CustomerName] = '" & RecID & "'"
 
R

ramblinwreck

After I do the requery, I use "seek" to find the record just created and then
I copy the fields from the table into 'me'. However, after this code
executes, I see the data from the first record in the table...
 
R

ramblinwreck

Just to be sure, if I run the code you indicate below, will the record just
created now be displayed in the form?

And I'm not entering the information as I look at it. I click a command
button that creates a record via code vice entering it from a form.

thanks.
 
S

scubadiver

A form can only use one table as its source OR a combination of connected
tables using a query.

My question is: why do you need to put the same information in two different
tables?
 
R

ramblinwreck

I'm not putting the same info in two different tables. The form is based on
a query.

How can I get the form to display the record just created?
 
R

ramblinwreck

ok, I tried the me.dirty=false.

As before, new record was created but with this line of code, the new record
doesn't even show up in my form although when I go to the table, the record
is there.
 
R

ramblinwreck

I can't exactly run the code you suggest below because your code appears to
assume that the form is displaying the value of the unique field when the
requery is executed. The form is not displaying any data at all from the new
record.
 
S

scubadiver

I have code that creates a new record using a command button and it works
fine. Can you post your code that creates the record?
 
R

ramblinwreck

Ok,

Here's the code:

Private Sub cmdNewPartThisMaintenance_Click()
On Error GoTo Error_Handler:
Dim dbs As Database
Dim rst As DAO.Recordset
Dim lngMaintNo As Long
Dim inttest As Integer
Dim intcompanykey As Integer
'check to make sure an entry has been made in the frmMaintenanceEntries
txtDescription field
If IsNull(Me.txtDescription) Then
MsgBox "You must enter a description of the maintenance entry before
proceeding.", vbCritical, "Home Maintenance Records"
GoTo exit_procedure
End If
'arriving at this point in the code means an entry has already been made in
the txtDescription field of frmMaintenanceEntries and therefore the associated
'record in the tblMaintenanceList has already been created
'assign value from field txtEntryNo of the frmMaintenanceEntries form to
lngMaintNo
lngMaintNo = Me.txtEntryNo
Set dbs = CurrentDb
'now open the parts info table
Set rst = dbs.OpenRecordset("tblpartsinfo", dbOpenDynaset)
'add new record with llngzmaintentrynolink equal the variable
With rst
.MoveLast
.AddNew
!llngzMaintEntryNoLink = lngMaintNo
'update the record
.Update
.MoveLast
inttest = !idsPartsInfoID
End With
Close
Set rst = Nothing
Set rst = dbs.OpenRecordset("tblCompanyInformation", dbOpenDynaset)
With rst
.AddNew
!lngzPartsKey = inttest
!lngzmaintenancekey = lngMaintNo
.Update
.MoveLast
intcompanykey = !idsCompanyInfoID
End With
Close
Set rst = Nothing
Set rst = dbs.OpenRecordset("tblPartsinfo", dbOpenTable)
With rst
.Index = "idspartsinfoid"
.Seek "=", inttest
.Edit
!lngzCompanyInfoLink = intcompanykey
.Update
End With
exit_procedure:
Close
Set rst = Nothing
DoCmd.Hourglass False
DoCmd.SetWarnings True
DoCmd.Requery
'Forms("frmMaintenanceEntries").Refresh
Exit Sub
Error_Handler:
On Error Resume Next
MsgBox "An error has occurred in this application. " _
& "Please contact your technical support person and tell them this
information:" _
& vbCrLf & vbCrLf & "Error Number " & Err.Number & ", " & Err.Description, _
Buttons:=vbCritical, title:="Motorhome Maintenance Records"
Resume exit_procedure
Resume

End Sub
 
C

Charlie

Hi Rick, I have the same probelm.

Basically I have a bound from with a combo box to select the desired record.
Problem 1
When i create a new record the combo box displays the previous recordID
Problem 2
I have a couple of unbound list boxes that should requery after the new record has been insterted, however they don't, but instead display the old data from the previously displayed record.
No amount of Requerying on the Form or Control events, seems to make a difference.

Have you any ideas as I've been at it for the past 3 hours and haven't managed to find a solution?

Cheers

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

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