Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MIcrosoft, Access, 2003, VB - Populate an array from record set - Part Two, Get errors... "Type Mismatch" OR "Can't Assign to Array"

Posted on 2007-11-28
3
Medium Priority
?
4,487 Views
Last Modified: 2013-11-27
All I want to do is display the Record Set on screen (only if records are found) in table format or perhaps print it; which ever is easier.

However; I continually get one of these errors... "Type Mismatch" OR "Can't Assign to Array"

I have found a couple of previous questions that are good examples, however neither solution resolves my problem...
http://search.experts-exchange.com/Microsoft/Development/MS_Access/Q_20844364.html?sfQueryTermInfo=1+arrai+assign+can%27t

http://search.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_22864730.html?sfQueryTermInfo=1+arrai+assign+can%27t

My code is attached.
Function FindDuplicates()
   Dim DB As Database
   Dim TheRecordSet As Recordset
   Dim RecordSetArray() As Variant     '<----- Related to error
   Dim NumOfRecords, RSRows, RSCols As Long
   Dim ModuleName, ErrorText, SQLQuery1 As String
   
   ' Initialize Error Routine
   On Error GoTo ThreeStoogages
   ModuleName = "FindDuplicates()" & Chr(10) & Chr(13)
   ErrorText = ModuleName & Chr(13) & Chr(10) & "Initialize All Variables"
   
   Set DB = CurrentDb()
   NumOfRecords = 0
   
   MsgBox "Begin VB Module Process: " & ModuleName & Chr(13) & Chr(10) & "Is used to identify duplicate records", vbInformation, "VB Module Execution"
   
   ' The SELECT Query
   SQLQuery1 = "SELECT blah, blah, blah..."
   ' MsgBox SQLQuery1, vbInformation, "SQLQuery1 Variable Contents"
   
   ' Create the RecordSet
   ErrorText = ModuleName & Chr(13) & Chr(10) & "Initialize Record Set"
   Set TheRecordSet = DB.OpenRecordset(SQLQuery1, dbOpenSnapshot)
   TheRecordSet.MoveLast
   TheRecordSet.MoveFirst
   NumOfRecords = TheRecordSet.RecordCount
   
   ' Store the Record Set into an Array
   ErrorText = ModuleName & Chr(13) & Chr(10) & "Store the Record Set in an Array"
   Set RecordSetArray = TheRecordSet.GetRows(NumOfRecords)     '<----- Error occurs here
   
   ' Get the Array Column and Row Count
   ErrorText = ModuleName & Chr(13) & Chr(10) & "Get the Column and Row counts in the Array"
   RSCols = UBound(RecordSetArray, 1) 'Returns the Number of Columns in the Record Set - I have 9 columns
   RSRows = UBound(RecordSetArray, 2) 'Returns the Number of Rows in the Record Set - I have 120 records
   
   ' For the Error Routine
   ErrorText = ModuleName & Chr(13) & Chr(10) & "Check for empty Record Set"
   If TheRecordSet.BOF And TheRecordSet.EOF Then
      MsgBox ModuleName & Chr(13) & "No duplicate records found.", vbInformation, "Successful VB Module Execution"
      Exit Function
   Else
      ' Display the Record Set on screen
      ErrorText = ModuleName & Chr(13) & Chr(10) & "Display Record Set"
      MsgBox ModuleName & Chr(13) & "Duplicate records found.", vbInformation, "Successful VB Module Execution"
      
      ' Write any display code here as needed
      
   End If
   
   MsgBox ModuleName & "Found " & NumOfRecords & " Duplicate Records", vbInformation, "Successful VB Module Execution"
   Exit Function
   
' Error Routine
ThreeStoogages: MsgBox "Error Type: " & Error() & Chr(13) & Chr(10) & ErrorText, vbInformation, "Un-Successful VB Module Execution"
 
End Function

Open in new window

0
Comment
Question by:Frank Bryant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85
ID: 20367646
Try declaring your array differently:

Dim RecordSetArray As Variant     '<----- Related to error

See this KB article for more info:
http://support.microsoft.com/kb/129856
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 750 total points
ID: 20367653
Note also you may need to remove teh Set call:

RecordSetArray = TheRecordSet.GetRows(NumOfRecords)
0
 

Author Comment

by:Frank Bryant
ID: 20373415
LSMConsulting,

Thanks, I use this declaration... Dim RecordSetArray() As Variant ...and removed the word SET per your sugestion and it worked! That explains why I coulsd not figure it out, it wasy to easy.

Now all I need to do is display the array in a table or grid, any suggestions (point me in the right direction)?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question