ADO recordset not working. What's wrong with this code?

TIbbs

Registered User.
Local time
Today, 17:09
Joined
Jun 3, 2008
Messages
60
I have used ADO regularly to access my data with not many problems. But I have been having some problems, with this code in particular:

Code:
Public Function ErrorExist() As Boolean
Dim SkuError As Boolean
Dim sSQL As String
Dim varMyErrors As Variant



sSQL = "SELECT Count(qryPOPExportCheck.intOrderNumber) AS CountOfOrder " & _
"FROM qryPOPExportCheck;"

Set cnn = CurrentProject.Connection
    'set the recordset
Set rst = New ADODB.Recordset
rst.CursorType = adOpenStatic
rst.LockType = adLockOptimistic
rst.Open sSQL, cnn, adCmdText

varMyErrors = rst.Fields("CountOfOrder")

If varMyErrors > 0 Then

     SkuError = True

  Else

 SkuError = False
  End If
  
rst.Close
Set rst = Nothing

' Close Connection to database
cnn.Close
Set cnn = Nothing

ErrorExist = SkuError
End Function
Private Sub CheckErrors_Click()
On Error GoTo Err_CheckErrors_Click


If ErrorExist = True Then




DoCmd.SetWarnings False
DoCmd.OpenQuery "qryPOPExportCheck", acViewNormal, acEdit
DoCmd.OpenQuery "qryPOPImport", acViewNormal, acEdit
DoCmd.SetWarnings True


Else

MsgBox ("No Errors")


End If



'Error handling
Exit_CheckErrors_Click:
Exit Sub

Err_CheckErrors_Click:
MsgBox Err.Description
Resume Exit_CheckErrors_Click


End Sub
I am trying to check a series of errors for an imported table, the other modules work perfectly, but I keep on getting the message No Errors in this module, even though there are errors in my error table.??? :mad:
My qryPOPexportCheck has a series of IIf functions. Could that be the cause?
 
At what point are you getting the error and what is the error? Have you stepped through the code?
 
every time I stepped through the code it went straight to the Message box MsgBox ("No Errors").
Actually as I needed to make it work fast I used DAO in this one. I used Dlookup, which is fine as it's only an administrator task, so speed is not an issue, I ended up with the following:

Code:
Public Function ErrorExist() As Boolean
Dim SkuError As Boolean
Dim varMyErrors As Variant


varMyErrors = DCount("intOrderNumber", "qryPOPExportCheck")

If varMyErrors > 0 Then

     SkuError = True

  Else

 SkuError = False
  End If
  
ErrorExist = SkuError
End Function

And bellow is the sub that calls the function:

Code:
Private Sub cmdCheckPOPImport_Click()
On Error GoTo Err_cmdCheckPOPImport_Click

'Check data entered correctly in the form.

 ValFormInput

'Check to see if POP Import table has any data in
          If CheckHasData = False Then

MsgBox ("There are no values in the POP Import table. Use the form to enter new values")
Exit Sub

Else
 'Update POP Import
DoCmd.SetWarnings False
DoCmd.OpenQuery "udtImportPOPSku", acViewNormal, acReadOnly
DoCmd.SetWarnings True
 End If


'Check for Errors
If ErrorExist = True Then
 
 MsgBox ("Several errors where found, please correct and start again.")
   DoCmd.SetWarnings False
           DoCmd.OpenQuery "qryPOPExportCheck", acViewNormal, acEdit
           DoCmd.OpenQuery "qryPOPImport", acViewNormal, acEdit
           DoCmd.SetWarnings True
 
Exit Sub
Else

'Check for input in fields supplier and order in the form.
'Process data accordingly.

     If HasSuppOrder = False Then
     
UpdatePOPTables
     
     Else
     
     MatchSuppOrder
     
    End If
    
End If
           
'Error handling
Exit_cmdCheckPOPImport_Click:
    Exit Sub

Err_cmdCheckPOPImport_Click:
    MsgBox Err.Description
    Resume Exit_cmdCheckPOPImport_Click

End Sub

It's a bit of a messy code, but we are dealing with imported data and we need to format it to match our data.
 

Users who are viewing this thread

Back
Top Bottom