Solved

From array to table

Posted on 2000-03-07
3
148 Views
Last Modified: 2010-05-02
I Filledup two 2.dimensinal arrays.I wont to check value in several col. of first array  wiht value in a second col. of second array and if value the same I want to replace value from first with value in second array.I have pice of code and I am not sure is it Ok. After I did this I wont to fillup access table with first array. Whent  I try this I am geting error: trying to assaign Null value to variable which is not variant type. I am not sure where I am making mistake. I Checke table filds types to be sure it looks ok.
Here is pice of code which I am using
Dim PullPatientSpec(5950, 23) As Variant
Dim Pullcode(344, 4) As Variant

Dim rowp As Integer
Dim colp As Integer
Dim rowc As Integer
Dim colc As Integer

For rowp = 0 To 5950
For colp = 4 To 14
    For rowc = 0 To 344
    colc = 1
       
        If Pullcode(rowc, colc) = PullPatientSpec(rowp, colp) Then
            PullPatientSpec(rowp, colp) = Pullcode(rowc, colc + 1)
         End If
   
    Next rowc
Next colp
Next rowp

And Part for fillup access table
Set rsTemp = dbDatabase.OpenRecordset("TempPatientSpecific", dbOpenDynaset)

rsTemp.AddNew
Dim PullPatientSpec(5950, 23) As Variant
Dim rowp As Integer
Dim colp As Integer

For rowp = 0 To 5950
rsTemp.AddNew
For colp = 0 To 23
rsTemp.Fields(colp) = PullPatientSpec(rowp, colp)

Next colp
rsTemp.Update
Next rowp

0
Comment
Question by:backroads
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
samopal earned 100 total points
ID: 2592919
It's a common mistake - try to assign NULL value to Access field. Change the line rsTemp.Fields(colp)=... to
If not IsNull(PullPatientSpec(rowp, colp) Then rsTemp.Fields(colp) = PullPatientSpec(rowp, colp)


HTH

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2594730
Wait a second samopal.. read the code again.. backroads is looping too many times through the code for BOTH tables!!!

Dim PullPatientSpec(5950, 23) As Variant

The PullPatient Spec is defined as 5950 rows.. since VB arrays (unless explicitly overridden) are zero based, that means index values can only be in the range of 0 to 5949.. as such.. the FOR loop statement he uses..

For rowp = 0 To 5950

is definitely going to error out because he is exceeding the end of the array on the last pass.

Backroads.. adjust your loops accordingly, k?





0
 
LVL 9

Expert Comment

by:samopal
ID: 2596100
To wsh2: Look at Backroad's original message:
<I try this I am geting error: trying to assaign Null value to variable
What you found is a mistake, but it's ahead :-)))
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace Formatted Numbers with text 9 61
Problem to skip loop 6 55
Recommendation vb6 to vb.net or others 14 112
Excel Automation VBA 19 38
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now