Re: Invalid Procedure Call
- From: "Gary Walter" <gary@xxxxxxxxxxx>
- Date: Wed, 15 Aug 2007 06:07:10 -0500
<nick.terry wrote :
Ok, this is a bit hard to classify, but it uses SQL and references<snip>
queries, so here goes...
I completed a database last thursday, and went to back it up and make
several copies. Unfortunatly in my rush to backup, I backed up the
wrong file and deleted the finished one. Luckily, I was able to
restore from a backup the night before, and only lost 1 days work.
Unfortunatly, now one of my modules will not work, giving me a generic
"Invalid Procedure Call" error. After extensive testing and
debugging, I have isolated the problem.
My module is designed to import a HUGE amount of data over ODBC from a
linked table, copy it to a local table for quick access, then format
the raw data (which involves the use of Mid and InStr) to insert into
a working table.
This is done with about 9 SQL strings total, including error
handling. My problem is occuring in the SQL string that takes the raw
data from the local table, formats it, and appends it to the final
table.
Raw Data Table: pipointlocal
Fields: tag, pointid, date
Finished Table: TagTable
Fields: PointTag, Station, TagName, PointID
SQL:
INSERT INTO TagTable ( PointTag, Station, TagName , PointID )
SELECT [pipointlocal].[tag], Mid([pipointlocal].[tag],4,InStr(4,
[pipointlocal].[tag],'_')-4) AS Station, Mid([pipointlocal].
[tag],InStr(4,[pipointlocal].[tag],'_')+1) AS TagName, [pipointlocal].
[PointID]
FROM pipointlocal;
'tag is a concatenated string which contains a station and a
'tag name, so the left and mid funtions slice it up into its
'respective parts
This SQL statement is put into a string and executed in VBA.
If I use the SQL in a query, it works fine. It only creates a problem
when executed using VBA.
Hi Nick,
You don't mention Access nor Windows version,
but a WAG might involve the difference of "compare"
between QBE and VBA for your InStr function
(for which you have chosen to assume "default").
Again as a real WAG, I might first try adding text compare (=1)
because it "works" in QBE but not in VBA
INSERT INTO TagTable ( PointTag, Station, TagName , PointID )
SELECT
P.[tag],
Mid(P.[tag],4,InStr(4,P.[tag],'_',1)-4) AS Station,
Mid(P.[tag],InStr(4,P.[tag],'_',1)+1) AS TagName,
P.[PointID]
FROM
pipointlocal AS P;
Above assumes that SQL has been properly
formed in VBA string (no " within quotes,etc)
which I usually test by adding
Debug.Print strSQL
after assembling strSQL in VBA.
And I assume you have removed 2 parsing
lines to verify they are the problem (maybe
remove one then the other to limit if can).
Next place I might look is what values "tag"
might have (and question assumptions I am
making about "tag").
SELECT DISTINCT
P.[tag],
Len(P.[tag]) As TagLen,
InStr(1, P.[tag],'_',1) As FirstPos
FROM
pipointlocal AS P;
Once I fully understood the variants
of "tag" values, then I might look to
see where values outside my previous
assumptions would cause me to change
my parsing.
I really don't understand your parsing
for "Station" and "TagName."
It looks like you already
assume the "_" will be at pos 4?
Or will always occur on or after pos 4?
Can there be more than one "_" in string?
Or possibly a "tag" with no "_" char?
So following won't work?
Left(P.[tag], InStr(P.[tag],'_') -1) As Station,
Mid(P.[tag],InStr(P.[tag],'_')+1) AS TagName,
or
Left(P.[tag], InStr(1,P.[tag],'_',1) -1) As Station,
Mid(P.[tag],InStr(1,P.[tag],'_',1)+1) AS TagName,
in Immediate Window...
tag=null
?Mid(tag,4,InStr(4,tag,'_',1)-4) <--compile error
?Mid(tag,4,InStr(4,tag,'_',1)+1) <--compile error
What happens if you use an IIF test before your parsing?
(or in WHERE clause to weed out "bad tags")
Of course a problem with References can cause
your error message, but you said it "works"
as a query alone.
If above WAGS do not help, please provide
a list of all the various types of values "tag" can
be.
Good Luck,
gary
.
- Follow-Ups:
- Re: Invalid Procedure Call
- From: nick . terry
- Re: Invalid Procedure Call
- References:
- Invalid Procedure Call
- From: nick . terry
- Invalid Procedure Call
- Prev by Date: Address fields left
- Next by Date: Re: Replace Values instead by FORM
- Previous by thread: Invalid Procedure Call
- Next by thread: Re: Invalid Procedure Call
- Index(es):
Relevant Pages
|