title: VB6 Assigning data to variables from a database
body: <p>I've been asked to make a change to a VB6 project. The issue I'm having is that I'm trying to get some data from an Access database and assign the data to some variables.</p>
  
  <p>I've got the code:</p>
  
  <pre><code>Dta_Period.DatabaseName = DB_Accounts_Name$
  Dta_Period.RecordSet = "SELECT * FROM [Period]"
  Dta_Period.Refresh
  </code></pre>
  
  <p>The table <code>Period</code> contains 2 fields. <code>sMonth</code> and <code>Period</code>
  The <code>sMonth</code> field contains the months January - December. The <code>Period</code> field stores a number 0 to 11, to represent what number has been assigned to which month in the customers financial year. January may be 0, or may be 11, essentially.</p>
  
  <p>I need to know which month goes with which period, which is why I have selected this data from the database. However, I'm stuck with what to do next.</p>
  
  <p>How can I loop over the <code>RecordSet</code> (If this is even possible?) and find out what number has been assigned to each month? </p>
  
  <p>I don't think there is a way I can use a <code>Do Until</code> loop. Is it easier to just use 12 separate queries, and then create an array of strings and an array of integers and then loop over the array of strings until I find the correct month, the use the same index for the array on integers?</p>
  
  <p><em>EDIT 1</em></p>
  
  <p>To make things simpler to follow for both myself and anyone attempting to provide an answer, I have modified the code.</p>
  
  <pre><code>Dim rstPeriod As DAO.RecordSet
  Dim accDB As DAO.Database
  
  ' DB_Session is a Workspace, whilst DB_Accounts_Name$ is the name of the DB I am using
  Set accDB = DB_Session.OpenDatabase(DB_Accounts_Name$)
  
  SQL = "SELECT * FROM [Period] ORDER BY [Period]"
  
  Set rstPeriod = accDB.OpenRecordset(SQL, dbOpenDynaset)
  
  If rstPeriod.BOF = False Then
     rstPeriod.MoveFirst
  End If
  
  Dim strMonth(11) As String
  Dim pNumber(11) As Integer
  </code></pre>
  
  <p>Pseudocode idea:</p>
  
  <pre><code>Do Until rstPeriod.EOF
     Select Case currentRow.Field("Month")
       Case "January"
         strMonth(0) = "January"
         pNumber(0) = currentRow.Field("Number")
       Case "February"
         strMonth(1) = "February"
         pNumber(1) = currentRow.Field("Number")
      End Select
  Loop
  </code></pre>