Connecting Tech Pros Worldwide Forums | Help | Site Map

not able to navigate recordset

Newbie
 
Join Date: Aug 2007
Posts: 20
#1: Aug 30 '07
Hi, I am new VB programming in Access and I am requesting help with the following code.

This code is attached to a form that will display a specific recordset based in information passed to the form from another form. The problem I am having is that for each of the case statements the proper records (values and Number of records) are being returned but the movement commands do not work, only the first record in the set is displayed. I can use the troubleshooting code to advance the recordset to any point in the file at which the display is blank until I click the cmdMoveFirst button. I’m missing something. I don’t think it is the code for the nav buttons thats' pretty simple stuff. From what research I’ve done I think/suspect, but mostly guess it’s the cursor type and location. Any help would be greatly appreciated, especially tips on trouble shooting this type of problem.

TIA

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4.  
  5. Dim SQL As String
  6. Dim cmdFormPop As ADODB.Command
  7. Dim cnn As ADODB.Connection
  8. Dim fldUserAssignment As ADODB.Field
  9. 'Dim prmValue1 As ADODB.Parameter
  10. Dim S1 As Integer
  11.  
  12.  
  13.     Set cmdFormPop = New Command
  14.     Set cmdFormPop.ActiveConnection = CurrentProject.Connection
  15.  
  16.  
  17.     S1 = gUserAssignment  'pass user ID to parameter value
  18.  
  19.     Debug.Print gFormState
  20.  
  21.     With gRS
  22.         .CursorType = adOpenDynamic
  23.         .CursorLocation = adUseServer
  24.         .LockType = adLockBatchOptimistic
  25.     End With
  26.  
  27.     Select Case gFormState
  28.  
  29.     Case "Unworked"
  30.  
  31.  
  32.         cmdFormPop.CommandType = adCmdText
  33.         cmdFormPop.CommandText = "SELECT CLAMNO,VENDNM,Question1 FROM PPmaster " & _
  34.             "WHERE ((PPmaster.UserAssignment) = ? And (PPmaster.Question1) = 1);"
  35.  
  36.         Set prm0 = cmdFormPop.CreateParameter("prmUserAssignment", adVarChar, adParamInput, 15)
  37.         prm0.Value = S1
  38.  
  39.         cmdFormPop.Parameters.Append prm0
  40.  
  41.         Set gRS = cmdFormPop.Execute
  42.  
  43.  
  44.     Case "Worked"
  45.  
  46.         cmdFormPop.CommandType = adCmdText
  47.         cmdFormPop.CommandText = "SELECT CLAMNO,VENDNM,Question1 FROM PPmaster " & _
  48.             "WHERE ((PPmaster.UserAssignment) = ? And (PPmaster.Question1) <> 1);"
  49.  
  50.         Set prm0 = cmdFormPop.CreateParameter("prmUserAssignment", adVarChar, adParamInput, 15)
  51.         prm0.Value = S1
  52.  
  53.         cmdFormPop.Parameters.Append prm0
  54.  
  55.         Set gRS = cmdFormPop.Execute
  56.  
  57.  
  58.     Case "All"
  59.  
  60.         cmdFormPop.CommandType = adCmdText
  61.         cmdFormPop.CommandText = "SELECT CLAMNO,VENDNM,Question1 FROM PPmaster " & _
  62.             "WHERE (PPmaster.UserAssignment) = ?;"
  63.  
  64.         Set prm0 = cmdFormPop.CreateParameter("prmUserAssignment", adVarChar, adParamInput, 15)
  65.         prm0.Value = S1
  66.  
  67.         cmdFormPop.Parameters.Append prm0
  68.  
  69.         Set gRS = cmdFormPop.Execute
  70.  
  71.     End Select
  72.  
  73.  
  74.     'troulbe shooting code to validatecorrect records are returned
  75.  
  76.     Do Until gRS.EOF
  77.         Debug.Print gRS.Fields(0)
  78.         Debug.Print gRS.Fields(1)
  79.         Debug.Print gRS.Fields(2)
  80.                 gRS.MoveNext
  81.     Loop
  82.  
  83.             Debug.Print "record count: "; gRS.RecordCount
  84.  
  85.  
  86.     gRS.MoveFirst
  87.  
  88.     'MasterDisplay is a seperate module that will dispaly all of
  89.     'the fields in a single instance instead of under each move control
  90.  
  91.     'MasterDisplay
  92.  
  93.  
  94. End Sub
  95. Public Sub cmdMoveFirst_Click()
  96.  
  97.     On Error GoTo DbError
  98.  
  99.     'Move to the first record in the result set.
  100.     gRS.MoveFirst
  101.  
  102.         Forms!frmMasterDisplayA!txtCLAMNO = gRS.Fields(0)
  103.         Forms!frmMasterDisplayA!txtQuestion1 = gRS.Fields(1)
  104.         Forms!frmMasterDisplayA!txtVENDNM = gRS.Fields(2)
  105.  
  106.  
  107.         'MasterDisplay is a seperate module that will dispaly all of
  108.             'the fields in a single instance instead of under each move control
  109.  
  110.         'MasterDisplay
  111.  
  112.     Exit Sub
  113.  
  114. DbError:
  115.  
  116.     MsgBox "There was an error retrieving information " & _
  117.         "from the database." _
  118.         & Err.Number & ", " & Err.Description
  119.  
  120. End Sub
  121.  
  122. Public Sub cmdMoveLast_Click()
  123.  
  124.     On Error GoTo DbError
  125.  
  126.     'Move to the last record in the result set.
  127.     gRS.MoveLast
  128.  
  129.         Forms!frmMasterDisplayA!txtCLAMNO = gRS.Fields(0)
  130.         Forms!frmMasterDisplayA!txtQuestion1 = gRS.Fields(1)
  131.         Forms!frmMasterDisplayA!txtVENDNM = gRS.Fields(2)
  132.  
  133.  
  134.         'MasterDisplay is a seperate module that will dispaly all of
  135.             'the fields in a single instance instead of under each move control
  136.  
  137.         'MasterDisplay
  138.  
  139.     Exit Sub
  140.  
  141. DbError:
  142.  
  143.     MsgBox "There was an error retrieving information " & _
  144.         "from the database." _
  145.         & Err.Number & ", " & Err.Description
  146.  
  147. End Sub
  148.  
  149. Public Sub cmdMoveNext_Click()
  150.  
  151.     On Error GoTo DbError
  152.     'Move to the next record in the result set if the cursor is not
  153.     'already at the last record.
  154.     If gRS.AbsolutePosition < _
  155.         gRS.RecordCount Then
  156.  
  157.         gRS.MoveNext
  158.  
  159.         Forms!frmMasterDisplayA!txtCLAMNO = gRS.Fields(0)
  160.         Forms!frmMasterDisplayA!txtQuestion1 = gRS.Fields(1)
  161.         Forms!frmMasterDisplayA!txtVENDNM = gRS.Fields(2)
  162.  
  163.  
  164.         'MasterDisplay is a seperate module that will dispaly all of
  165.             'the fields in a single instance instead of under each move control
  166.  
  167.         'MasterDisplay
  168.  
  169.  
  170.     End If
  171.  
  172.     Exit Sub
  173.  
  174. DbError:
  175.  
  176.     MsgBox "There was an error retrieving information " & _
  177.         "from the database." _
  178.         & Err.Number & ", " & Err.Description
  179.  
  180. End Sub
  181.  
  182. Public Sub cmdMovePrevious_Click()
  183.  
  184.     On Error GoTo DbError
  185.  
  186.     'Move to the previous record in the result set, if the
  187.     'current record is not the first record.
  188.     If gRS.AbsolutePosition > 1 Then
  189.  
  190.         gRS.MovePrevious
  191.  
  192.         Forms!frmMasterDisplayA!txtCLAMNO = gRS.Fields(0)
  193.         Forms!frmMasterDisplayA!txtQuestion1 = gRS.Fields(1)
  194.         Forms!frmMasterDisplayA!txtVENDNM = gRS.Fields(2)
  195.  
  196.  
  197.         'MasterDisplay is a seperate module that will dispaly all of
  198.             'the fields in a single instance instead of under each move control
  199.  
  200.         'MasterDisplay
  201.  
  202.     End If
  203.     Exit Sub
  204.  
  205. DbError:
  206.  
  207.     MsgBox "There was an error retrieving information " & _
  208.         "from the database." _
  209.         & Err.Number & ", " & Err.Description
  210.  
  211. End Sub

Reply