Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing to database 1

Status
Not open for further replies.

spruceni

Technical User
May 18, 2007
72
GB
Hi
I have created a form unbounded into which I get the user to enter some details. I then open a new record in the table and write in the details.

' Adds a new record to a Recordset using the data on the new form

With rstAddAction
.AddNew
!ActionNumber = Me.ActionNumber
!ActionType = Me.ActionType
!StdClauseID = Me.StdClauseID
!NonConf = Me.NonConf
!RootCause = Me.RootCause
!Action = Me.Action
!Progress = Me.Progress
!AuditID = Me.AuditID
!LaboratoryID = Me.LaboratoryID
!BusinessManID = Me.BusinessManID
!RespPerson = Me.RespPerson
!RaisedDate = Me.RaisedDate
!ToQualityDate = Me.ToQualityDate
!ToBMDate = Me.ToBMDate
!FromBMDate = Me.FromBMDate
!ActTargetDate = Me.ActTargetDate
!ActCompDate = Me.ActCompDate
!FollowUP = Me.FollowUP
!QMSignOff = Me.QMClose
!FollowUp2 = Me.FollowUp2

.Update
End With
' Clean up recordsets

rstAddAction.Close
Set rstAddAction = Nothing
Set db = Nothing

I note when examining the running of this code using debug the record is not written directly to the table and at this stage of the code there is no new record in the table.


What I wanted to do is to open the newly saved record in another form so that further data can be input but it is not there to open.

the record only seems to appear once I close the routine.

How do I force the record to be written when I do the .update command so at it appears in the table and I can operate on it.





 
As soon as the .Update runs is when the record will be added to the table. How are you confirming that it's been added? If you are keeping a datasheet view of the table open while running, you will probably not see the new record until you refresh the datasheet (and keep in mind that you won't necessarily see the new record on the bottom row).


 
How are ya spruceni . . .

If you enter a question [red]?[/red] in the [blue]Tag[/blue] property of the controls used in your code (no quotations please), you can condense your code to the following:
Code:
[blue]   rst.AddNew
   
   For Each ctl In Me.Controls
      If ctl.Tag = "[red][b]?[/b][/red]" Then
         If ctl.Name <> "QMClose" Then
            rst(ctl.Name) = Me(ctl.Name)
         Else
            rst!QMSignOff = Me(ctl.Name)
         End If
      End If
   Next
            
   rst.Update
   
   Set rst = Nothing
   Set db = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
spruceni

You 'll have to use the RefreshCache method of the JetEngine Object, to force pending data changes in the cache to be processed

 
Hi Guys

Thanks for the information. I will work on it a bit more.

Never thought of that, TheAceman1 :)

Regards

Spruceni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top