[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.2

Updating records from excel to access problem

Asked by sahi0002 in Microsoft Excel Spreadsheet Software, Microsoft Access Database

Hi, I have a database in MS Access.
I have a code for updating my records from excel to access. There is a field CA No and a field "Total Charges". CA No is a text field and total charges ia  currency field.

The code below matches the CA No of db with the excel datasheet's CA No column. Whenever CA No matches, a new duplicate record is created for that CA No and all the values of the fields of current record are copied onto the new record. The code was working more or less fine previously. But since I would have so many records with the same CA No after updating the db from excel mulitple times, hence I wanted a date field which will notify me of the date of creation and also only create the duplicate record of that CA No which is the newest ( or rather the latest record out of all the same CA Nos)
The date field is called Created Date.

The query that my module is based on is PBSorted:-

SELECT [PB Listing].[Contract ID], [PB Listing].[CA No], [PB Listing].[Total  Charges] and the field list continues...
 
FROM [PB Listing] INNER JOIN qryLastCA ON [PB Listing].[CA No] = [qryLastCA].[CA No] AND [PB Listing].[Date Created] = [qryLastCA].[MaxCreated]
WHERE [PB Listing].[CA No]
ORDER BY [PB Listing].[CA No];

qryLastCA:-
Select [PB Listing].[CA No], Max([Created Date]) as MaxCreated
FROM [PB Listing]
GROUP BY [PB Listing].[CA No]
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
VBA module (PB Listing is the name of my table):-
 
'UpdateCharges("x","x")
Public Function UpdateCharges(xlPath As String, wsName As String)
wsName = "cons_summary_20081231_starhub l"
 xlPath = "C:\Documents and Settings\Desktop\New Folder\sample.xls"
Stop
Dim xlApp As Excel.Application
Dim xlWb As Excel.Workbook
Dim xlWs As Excel.Worksheet
'Dim rsData As New ADODB.Recordset
Dim i As Long
Dim fCollection As New Collection
Dim fld As dao.Field
Dim rsData As dao.Recordset
Dim tblName As String
Dim CID As Variant
tblName = "PB Listing" ' Replace this with the name of your table
 
On Error Resume Next
' Try get a handle to a pre-existing copy of Excel
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ' Excel not open
    Set xlApp = New Excel.Application
    xlApp.Visible = True
End If
 
Set xlWb = xlApp.Workbooks.Open(xlPath, , True) ' open the workbook
Set xlWs = xlWb.Worksheets(wsName) ' get the correct worksheet
 
Set rsData = CurrentDb.OpenRecordset("PBSorted")  ' open our table
 
For i = 1 To xlWs.UsedRange.Rows.Count 
 
    rsData.MoveFirst
   CID = DLookup("[Contract ID]", tblName, "[CA No] = " & """" & xlWs.Cells(i, 1).Value & """")
    rsData.FindFirst "[CA No] = " & """" & xlWs.Cells(i, 1).Value & """"   
    Debug.Print rsData.Fields("CA No"), xlWs.Cells(i, 1).Value
    Debug.Print rsData.Fields("Contract ID")
    
    
    If "" = (xlWs.Cells(i, 1).Value) Then
    MsgBox ("Done")
    GoTo funclosethisout
    End If
    For Each fld In rsData.Fields ' keep track of current field values
        fCollection.Add fld.Value, fld.Name
    Next
   'If no match then need the new CA No.
   If rsData.NoMatch Then fCollection("CA No") = xlWs.Cells(i, 1).Value
 '  Stop
    rsData.AddNew ' create our new record
    
    For Each fld In rsData.Fields
        fld.Value = fCollection(fld.Name)       '  fld.Value = fCollection(fld.Name)
    
    Next
  'Stop
    ' reset our collection
    Set fCollection = Nothing
    Set fCollection = New Collection
    
    rsData.Fields("Total  Charges").Value = xlWs.Cells(i, 2).Value ' put in the new value
     
 rsData.Update
Next
funclosethisout:
xlWb.Close
xlApp.ActiveWorkbook.Close
xlApp.ActiveWindow.Close
Set xlApp = Nothing
End Function
[+][-]04/02/09 07:26 PM, ID: 24056225Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/02/09 07:44 PM, ID: 24056280Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/02/09 08:35 PM, ID: 24056424Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/02/09 08:37 PM, ID: 24056434Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/02/09 08:40 PM, ID: 24056443Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/02/09 08:45 PM, ID: 24056466Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/06/09 05:39 PM, ID: 24083126Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/08/09 06:34 PM, ID: 24103480Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/09/09 01:38 AM, ID: 24105223Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Excel Spreadsheet Software, Microsoft Access Database
Sign Up Now!
Solution Provided By: Tramtrak
Participating Experts: 2
Solution Grade: B
 
[+][-]04/09/09 02:33 AM, ID: 24105510Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/17/09 07:55 PM, ID: 24173338Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/20/09 04:45 AM, ID: 24183603Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/20/09 07:08 AM, ID: 24184718Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/21/09 12:39 AM, ID: 24191760Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/21/09 07:30 AM, ID: 24194817Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625