Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2009, 05:04 AM
Authorized User
 
Join Date: Sep 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA recordset problem

Hello,
I am having some difficulty in updating data using a form. I am using Access 2003, with SQL Server 2005.

I have a header table (tblJobs), a sub header table (tblJobSegment) and a line detail table (tblJobSegmentDetails).
I have a SQL view (vwJobSegmentSummary) which gathers data from the JobSegmentDetails table plus a number of other tables to generate the Job Segment Totals. (TotalCost, TotalSell. - Profit and GP can then be calculated as part of the update process).

What I am trying to do is to pass the values from the JobSegmentSummary view and update them to the JobSegment table.

The fields which I am trying to update are TotalCost, TotalSell, TotalProft, and TotalGP (Gross Profit).

Generally there are multplie Job Segments entries per job.

I have a query which holds the Totals for the Job Segment Table and the Totals for the Job Segment Summary view.
From the query I have created a continuous form which opens Job Segements for a Job, and lists which Job Segments belong to the job. the fields diplayed are:
tblJobSegment - JobNo, JobSegmentNo, TotalCost, TotalSell, TotalProfit, TotalGP.
vwJobSegmentSummary - TotalCost, TotalSell, TotalProfit, TotalGP.

I have an update button in the header section of the continuous form and have hobbled together the following code:

Private Sub cmdDoUpdate_Click()
On Error GoTo Err_cmdDoUpdate_Click

Dim rst As DAO.Recordset
Dim strQuery As String

Set dbs = CurrentDb
Set rst = Forms!frmTotalsUpdate.Recordset

rst.MoveFirst
With rst
Do Until .EOF

.Edit
Me!TotalCost.Value = [TotalCostCalc]
Me!TotalSell.Value = [TotalSellCalc]
Me!Profit.Value = [TotalSellCalc] - [TotalCostCalc]

If Me!TotalSell.Value = 0 Then
Exit Sub
Else
Me!GP.Value = [GPCalc]
End If

.Update
.MoveNext

Loop

End With

Exit_cmdDoUpdate_Click:

Exit Sub

Err_cmdDoUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdDoUpdate_Click

End Sub


When the code is run, the values do actually update on the continuous form and display as expected.
However, it is not updating the values in the Job Segment Table. I feel that maybe I have not referenced the recordset correctly.
I think I'm close to solving this but can't get past this last hurdle.

Any assistance would be really appreciated.

Dave
 
Old June 15th, 2009, 01:39 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can't use DAO with SQL Server 2005 (or any flavor). You have to use ADO if you want this to work. This will update the forms. I assume they are either not bound, or are bound to a non-updatable query.

I would process this as a separate transaction. What options and events do you have to work with?
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old July 1st, 2009, 01:47 AM
Authorized User
 
Join Date: Sep 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the delay in replying, I've been away.

Thanks for your answer.
The DAO vs ADO has been an area which has had me stumped on numerous occasions.
I think after reading quite a bit on this topic that I am finally strting to understand why I need to use ADO in this instance.
It means quite a change to how I am constructing this type of form, and I'm in the process of re-creating forms which will use ADO.

I suppose I'm still too early in the process to continue to ask questions in this thread, now that I've started to base this on ADO, but will come back to it once I get a little further down the track.

Thanks again for you reply.

Dave





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with recordset rwahdan BOOK: Access 2003 VBA Programmer's Reference 1 March 13th, 2008 05:03 AM
Recordset Problem hugoscp Classic ASP Professional 0 July 10th, 2007 05:59 AM
VBA recordset Stanny Excel VBA 1 October 19th, 2005 03:04 AM
MS Access, VBA code to copy recordset Ivan Classic ASP Databases 1 November 1st, 2003 05:52 PM
Problem In Recordset zaeem Classic ASP Databases 2 October 22nd, 2003 01:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.