Results 1 to 2 of 2

Thread: Checking Horizontally and vertically using ADO?

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Checking Horizontally and vertically using ADO?

    For the record, i am using ADODB, with VBA in MS Access 2002

    Current Code:

    VB Code:
    1. Private Sub personCalculations()
    2. '*******************************************************
    3. 'Opens the database and then opens the Workers table
    4. Set cn = New ADODB.Connection
    5. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    6.       "Data Source=C:\Documents and Settings\TSmith14\Desktop\test.mdb"
    7.     cn.Open
    8.     Set rs = New ADODB.Recordset
    9.     rs.Open "Workers", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    10. '********************************************************
    11. Do While rs.EOF = False
    12. '********************************************************
    13. 'Finds the academic payamount by comparing Current Payband from the
    14. 'Workers table, to the salary with the payband located in AcademicPayband
    15. If rs.Fields("Group") = "Academic" Then
    16.     Set RsPayband = New ADODB.Recordset
    17.     RsPayband.Open "AcademicPayband", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    18.     Do While RsPayband.EOF = False
    19.     If RsPayband.Fields("Payband") = rs.Fields("Current Payband") Then
    20.     academictotals = academictotals + RsPayband.Fields("Salary")
    21.     End If
    22.     RsPayband.MoveNext
    23.     Loop
    24.     RsPayband.Close
    25. '**********************************************************
    26. ElseIf rs.Fields("Group") = "Support" Then
    27.     Set RsPayband = New ADODB.Recordset
    28.     RsPayband.Open "Support Paybands", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    29.     Do While RsPayband.EOF = False
    30.    
    31.     Loop
    32.     RsPayband.Close
    33.    
    34. End If
    35. rs.MoveNext
    36. Loop
    37. rs.Close
    38. Label8.Caption = academictotals
    39. '********************************************************
    40.    
    41. End Sub

    Okay, well the academicpayband can find the values very easily, because it is just going through the file in sequential order, but now I am trying to do supportpayband, in which i need to deal with a database like this
    VB Code:
    1. Fields:  Payband,      Level1,      Level2,       Level3,      Level4,       Level5,    Level6
    2.              1         $##.##       $##.##        $##.##      $##.##         $##.##    $##.##
    3.              2         $##.##       $##.##        $##.##      $##.##         $##.##    $##.##        
    4.              3         $##.##       $##.##        $##.##      $##.##         $##.##    $##.##
    5.              4         $##.##       $##.##        $##.##      $##.##         $##.##    $##.##
    6.              5         $##.##       $##.##        $##.##      $##.##         $##.##    $##.##
    ***Sorry for the messy table, but I cant seem to get it right >.<***

    Now I need to go through, match the payband, then, match the level, and grab the corresponding value ($##.##) from the table.

    I have done multiple attempts at this, but it never seems to grab the value I want.

    Could anyone give me some hints on this?
    Last edited by kfcSmitty; May 20th, 2005 at 10:21 AM.

  2. #2

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Checking Horizontally and vertically using ADO?

    Not to double post or anything, but I fixed my problem (I think, it seems it be working). But the thing is, I dont really know WHY its working... Could someone explain the part I highlighted??

    VB Code:
    1. Private Sub personCalculations()
    2. totals = 0
    3. '*******************************************************
    4. 'Opens the database and then opens the Workers table
    5. Set cn = New ADODB.Connection
    6. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    7.       "Data Source=C:\Documents and Settings\TSmith14\Desktop\test.mdb"
    8.     cn.Open
    9.     Set rs = New ADODB.Recordset
    10.     rs.Open "Workers", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    11.     rs.MoveFirst
    12. '********************************************************
    13. Do While rs.EOF = False
    14. '********************************************************
    15. 'Finds the academic payamount by comparing Current Payband from the
    16. 'Workers table, to the salary with the payband located in AcademicPayband
    17. If rs.Fields("Group") = "Academic" And Me![List4] = "Academic" Then
    18.     Set RsPayband = New ADODB.Recordset
    19.     RsPayband.Open "AcademicPayband", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    20.     Do While RsPayband.EOF = False
    21.     If RsPayband.Fields("Payband") = rs.Fields("Current Payband") Then
    22.     totals = totals + RsPayband.Fields("Salary")
    23.     End If
    24.     RsPayband.MoveNext
    25.     Loop
    26.     RsPayband.Close
    27. '**********************************************************
    28. ElseIf rs.Fields("Group") = "Support" And Me![List4] = "Support" Then
    29. Dim strLevel As String
    30.     Set RsPayband = New ADODB.Recordset
    31.     RsPayband.Open "SupportPaybands", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    32.     RsPayband.MoveFirst
    33.     Do While RsPayband.EOF = False
    34.         strLevel = rs.Fields("Level")
    35.         If RsPayband.Fields("Payband") = rs.Fields("Current Payband") Then
    36.             If strLevel <> "0" Then
    37. '****************************************************
    38.                 If rs.Fields("Level") = rs.Fields("Level") Then
    39. '****************************************************
    40.                 Dim test As String
    41.                 test = rs.Fields("Level")
    42.                     totals = totals + RsPayband.Fields(test)
    43.                 End If
    44.             End If
    45.         End If
    46.        
    47.         RsPayband.MoveNext
    48.     Loop
    49.     RsPayband.Close
    50. End If
    51. rs.MoveNext
    52. Loop
    53. rs.Close
    54. Label8.Caption = totals
    55. '********************************************************
    56.    
    57. End Sub

    I don't really get why that selects the proper column for me....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width