To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Database Development

Reply Post New Thread
 
Thread Tools Display Modes
Old May 20th, 2005, 10:09 AM   #1
kfcSmitty
Frenzied Member
 
kfcSmitty's Avatar
 
Join Date: May 05
Location: Kingston, Ontario
Posts: 1,606
kfcSmitty is a jewel in the rough (200+)kfcSmitty is a jewel in the rough (200+)kfcSmitty is a jewel in the rough (200+)
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.
kfcSmitty is offline   Reply With Quote
Old May 20th, 2005, 12:00 PM   #2
kfcSmitty
Frenzied Member
 
kfcSmitty's Avatar
 
Join Date: May 05
Location: Kingston, Ontario
Posts: 1,606
kfcSmitty is a jewel in the rough (200+)kfcSmitty is a jewel in the rough (200+)kfcSmitty is a jewel in the rough (200+)
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....
kfcSmitty is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Database Development


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:29 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.