p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Access and Access VBA > Access VBA
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 15th, 2009, 06:04 AM
Authorized User
Points: 111, Level: 2
Points: 111, Level: 2 Points: 111, Level: 2 Points: 111, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: melbourne, VIC, Australia.
Posts: 17
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old June 15th, 2009, 02:39 PM
Friend of Wrox
Points: 9,516, Level: 42
Points: 9,516, Level: 42 Points: 9,516, Level: 42 Points: 9,516, Level: 42
Activity: 11%
Activity: 11% Activity: 11% Activity: 11%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 1st, 2009, 02:47 AM
Authorized User
Points: 111, Level: 2
Points: 111, Level: 2 Points: 111, Level: 2 Points: 111, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: melbourne, VIC, Australia.
Posts: 17
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with recordset rwahdan BOOK: Access 2003 VBA Programmer's Reference 1 March 13th, 2008 06:03 AM
Recordset Problem hugoscp Classic ASP Professional 0 July 10th, 2007 06:59 AM
VBA recordset Stanny Excel VBA 1 October 19th, 2005 04: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 02:34 AM



All times are GMT -4. The time now is 03:49 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc