UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Runtime Error 5 - I Can't Find The Problem, Office 2010    
 
   
bfras914
post Feb 23 2012, 12:42 PM
Post #1

New Member
Posts: 17
From: Connecticut



I'm getting a "Runtime Error 5 - Invalid procedure call or argument" error on what looks like a very simple line of code. I've been staring at it for hours, and I can't see any reason this should be causing an error. Below is a snippet of my code. When I debug, the error is occurring at the If...Then line.
For Y = 1 To X - 1
If strVend(Y) = strVend(X) Then
intVendMatch = intVendMatch + 1
End If
Next Y
At the point that the error occurs, the variable values are:
Y (Integer) = 1
X (Integer) = 2
strVend(1) (String) = "27539"
strVend(2) (String) = "27539"
Ocan't see any reason for an error message here. The If...Then statement should just compare the 2 values, see that they are equal, and move on. I've tried everything I can think of here. The problem may very well lie outside my project, but I'm a loss... Any advice would be greatly appreciated!
I'm running Office 2010 on Windows XP, by the way.
Go to the top of the page
 
+
Bob G
post Feb 23 2012, 12:52 PM
Post #2

UtterAccess VIP
Posts: 10,455
From: CT



where is the code for strvend ??
Go to the top of the page
 
+
bfras914
post Feb 23 2012, 01:15 PM
Post #3

New Member
Posts: 17
From: Connecticut



dim strVend(100) as String
alues are stored to this variable from a field in a recordset. I loop through the recordset once and store the value of this field into strVend() for each record. My X variable in the code from my first post represents the number of values that exist in the strVend() array.
Then later in the code I'm basically testing, for example, if the value in strVend(5) is the same as any of the values in strVend(1) through strVend(4). That's what this little section of code is supposed to do.
Go to the top of the page
 
+
bfras914
post Feb 24 2012, 09:12 AM
Post #4

New Member
Posts: 17
From: Connecticut



I still have no idea why I was getting this error, but I found a work-around. The values in strVend() will always be numeric, but it's a text field in the table I'm pulling it from. So that's why I was using a String variable. I added a line of code to convert the strings to numbers, and my procedure works fine when the If...Then statement is comparing numbers instead of strings.
don't really understand why it works with numbers and not strings, but I guess I'm all set now.
Go to the top of the page
 
+
Bob G
post Feb 24 2012, 09:25 AM
Post #5

UtterAccess VIP
Posts: 10,455
From: CT



you know you cannot compare strings to numbers unless they are made to look like either 2 strings or 2 numbers.
Go to the top of the page
 
+
bfras914
post Feb 24 2012, 12:03 PM
Post #6

New Member
Posts: 17
From: Connecticut



Yes, I know that. I started with 2 strings, and I was getting the runtime error. I converted both to numbers and didn't have the problem anymore.
Go to the top of the page
 
+
bfras914
post Mar 20 2012, 04:13 PM
Post #7

New Member
Posts: 17
From: Connecticut



I've encountered this error several other times since my original post, and I'm completely stumped. It seems that any time I have an If...Then comparing two strings to each other, I get the "Invalid Procedure Call or Argument" error message.
On the example I'm working on now, the debugger is pointing me to a line that reads:
If strName(X) = strName(Y) Then
strName() is an array defined as a string, so I'm comparing two values of the same data type.
Just for testing purposes, I changed that line to read:
If "X" = "Y" Then
Ostill got the same error.
I then changed that line to read:
If 1 = 2 Then
The code ran with no Runtime Error. Obviously that If...Then statement is never going to be true, but it seems to prove my theory that I can compare two integers without a problem, but any time I try to compare two strings in an If statement, I'm getting this error.
I don't recall ever seeing anything like this until recently, and now it seems to be happening all the time. I'm at a total loss here; if anyone knows what I'm doing wrong I'd really love to hear it!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 23rd October 2014 - 12:07 AM