Results 1 to 2 of 2

Thread: Code in Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    5

    Code in Access

    I am currently working on a form in access for a hiring plan. Basically what it will do is you will enter a number in a text box and it will populate what site(out of 4) based on prioity and number of available seats. What I need it to do is to go to the next site and if there is a remainder fill it in also. The final step will be to give me dates that the classes can start. Any thoughts?

    Private Sub txt_hiresneeded_AfterUpdate()

    Dim db As Database
    Dim frm As Form
    Dim rec As Recordset
    Dim mySQL As String

    'Below are calculated values
    Dim HireCapacity As Double
    Dim StationCapacity As Double
    Dim TrainingCapacity As Double
    Dim OpenStations As Double
    Dim SiteHires As Double

    'These values are pulled from a table or form
    Dim StatMultiplier As Double
    Dim TtlStations As Double
    Dim StationsInUse As Double
    Dim TraineesPerClass As Double
    Dim MaxClasses As Double
    Dim HiresNeeded As Double

    Set db = CurrentDb
    Set frm = Forms!frm_HireCapacity

    mySQL = "SELECT tbl_x65_sites.[Site Name], tbl_x65_sites.[Priority Code], tbl_x65_sites.[Stations], tbl_x65_sites.[Stations in use], tbl_x65_sites.[St Utiliz multiplier], tbl_x65_sites.[Class size limiter], tbl_x65_sites.[Training class limiter] FROM tbl_x65_sites WHERE (((tbl_x65_sites.[Priority Code])=1))"
    Debug.Print mySQL

    Set rec = db.OpenRecordset(mySQL)
    StatMultiplier = rec![St Utiliz multiplier]
    TtlStations = rec![Stations]
    StationsInUse = rec![Stations in use]
    TraineesPerClass = rec![Class size limiter]
    MaxClasses = rec![Training Class limiter]

    OpenStations = TtlStations - StationsInUse
    StationCapacity = OpenStations * StatMultiplier
    TrainingCapacity = TraineesPerClass * MaxClasses

    If TrainingCapacity > StationCapacity = True Then HireCapacity = StationCapacity Else HireCapacity = TrainingCapacity
    frm.txt_OneSite = rec![Site Name]
    frm.txt_OneSiteCapacity = HireCapacity

    HiresNeeded = frm.txt_hiresneeded
    If HiresNeeded < HireCapacity = True Then SiteHires = HiresNeeded Else SiteHires = HireCapacity
    frm.txt_OneSiteHires = SiteHires


    frm.Requery

    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    just tagging your code so I can read it:

    What piece are you actually having trouble with specifically?

    VB Code:
    1. I am currently working on a form in access for a hiring plan. Basically what it will do is you will enter a number in a text box and it will populate what site(out of 4) based on prioity and number of available seats. What I need it to do is to go to the next site and if there is a remainder fill it in also. The final step will be to give me dates that the classes can start. Any thoughts?
    2.  
    3. Private Sub txt_hiresneeded_AfterUpdate()
    4.  
    5. Dim db As Database
    6. Dim frm As Form
    7. Dim rec As Recordset
    8. Dim mySQL As String
    9.  
    10. 'Below are calculated values
    11. Dim HireCapacity As Double
    12. Dim StationCapacity As Double
    13. Dim TrainingCapacity As Double
    14. Dim OpenStations As Double
    15. Dim SiteHires As Double
    16.  
    17. 'These values are pulled from a table or form
    18. Dim StatMultiplier As Double
    19. Dim TtlStations As Double
    20. Dim StationsInUse As Double
    21. Dim TraineesPerClass As Double
    22. Dim MaxClasses As Double
    23. Dim HiresNeeded As Double
    24.  
    25. Set db = CurrentDb
    26. Set frm = Forms!frm_HireCapacity
    27.  
    28. mySQL = "SELECT tbl_x65_sites.[Site Name], tbl_x65_sites.[Priority Code], tbl_x65_sites.[Stations], tbl_x65_sites.[Stations in use], tbl_x65_sites.[St Utiliz multiplier], tbl_x65_sites.[Class size limiter], tbl_x65_sites.[Training class limiter] FROM tbl_x65_sites WHERE (((tbl_x65_sites.[Priority Code])=1))"
    29. Debug.Print mySQL
    30.  
    31. Set rec = db.OpenRecordset(mySQL)
    32. StatMultiplier = rec![St Utiliz multiplier]
    33. TtlStations = rec![Stations]
    34. StationsInUse = rec![Stations in use]
    35. TraineesPerClass = rec![Class size limiter]
    36. MaxClasses = rec![Training Class limiter]
    37.  
    38. OpenStations = TtlStations - StationsInUse
    39. StationCapacity = OpenStations * StatMultiplier
    40. TrainingCapacity = TraineesPerClass * MaxClasses
    41.  
    42. If TrainingCapacity > StationCapacity = True Then HireCapacity = StationCapacity Else HireCapacity = TrainingCapacity
    43. frm.txt_OneSite = rec![Site Name]
    44. frm.txt_OneSiteCapacity = HireCapacity
    45.  
    46. HiresNeeded = frm.txt_hiresneeded
    47. If HiresNeeded < HireCapacity = True Then SiteHires = HiresNeeded Else SiteHires = HireCapacity
    48. frm.txt_OneSiteHires = SiteHires
    49.  
    50.  
    51. frm.Requery
    52.  
    53. End Sub

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