Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default InStr and ADO

When I use the Instring function (instr) in Access, it
works fine, however, when I use it in the following Excel
procedure, it says "invalid" function or procedure.
The Excel Procedure creates a table in an Access Database
from another table.

Is the Instr function supposed to be spelled differently
in ADO? Or do I need to create this function in Access?
Thanks in advance.


Sub ExtractUniqueStylesByClass()
Dim cn As ADODB.Connection, RS As ADODB.Recordset, r As
Long
Dim Targetrange As Range
Dim intColIndex As Integer

Select Case TableXists("UNIQUESTYLESBYCLASS")
Case "TRUE"
DeleteAccessTable ("UNIQUESTYLESBYCLASS")
Case Else
End Select

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=K:\MPS\DATA\GMDATABASE.mdb;"
' open a recordset
Set RS = New ADODB.Recordset

'Create Table for Weekly Receipts By Class Report

SELECTOR = "SELECT RESVDATA.CLASS,(Left(RESVDATA.[MFG
STYLE],((InString(RESVDATA.[MFG STYLE],' * '))-1))) AS
STYLE INTO UNIQUESTYLESBYCLASS"

FROMCLAUSE = "FROM RESVDATA"

GROUPCLAUSE = "GROUP BY RESVDATA.CLASS, ((InStr(RESVDATA.
[MFG STYLE],' * '))-1)));"

strsql = SELECTOR & " " & FROMCLAUSE '& " " & GROUPCLAUSE

With RS
RS.Open strsql, cn, , , -1
End With

Set RS = Nothing
Set RS = New ADODB.Recordset

cn.Close
Set cn = Nothing

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default InStr Solution

The Instr works fine within ADO. Once I corrected the
parentheses, the sub worked fine.

Sub ExtractUniqueStylesByClass()
Dim cn As ADODB.Connection, RS As ADODB.Recordset, r As
Long
Dim Targetrange As Range
Dim intColIndex As Integer

Select Case TableXists("UNIQUESTYLESBYCLASS")
Case "TRUE"
DeleteAccessTable ("UNIQUESTYLESBYCLASS")
Case Else
End Select

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=K:\MPS\DATA\GMDATABASE.mdb;"
' open a recordset
Set RS = New ADODB.Recordset

'Create Table for Weekly Receipts By Class Report

SELECTOR = "SELECT RESVDATA.CLASS,(LEFT([RESVDATA].[MFG
STYLE],((InStr([RESVDATA].[MFG STYLE],'*'))-1))) AS STYLE
INTO UNIQUESTYLESBYCLASS"

FROMCLAUSE = "FROM RESVDATA"

GROUPCLAUSE = "GROUP BY RESVDATA.CLASS, (LEFT([RESVDATA].
[MFG STYLE],((InStr([RESVDATA].[MFG STYLE],'*'))-1)));"

strsql = SELECTOR & " " & FROMCLAUSE & " " & GROUPCLAUSE

With RS
RS.Open strsql, cn, , , -1
End With

Set RS = Nothing
Set RS = New ADODB.Recordset

cn.Close
Set cn = Nothing

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default InStr and ADO

Not sure about ADO with Access, but with SQL an equivalent string I use is
something like

LEFT(M.ItemName, CHARINDEX('*',M.ItemName)-1)

I haven't bother changing the variables to match your query.

Might as well give it a try.

Robin Hammond
www.enhanceddatasystems.com

"Al" wrote in message
...
When I use the Instring function (instr) in Access, it
works fine, however, when I use it in the following Excel
procedure, it says "invalid" function or procedure.
The Excel Procedure creates a table in an Access Database
from another table.

Is the Instr function supposed to be spelled differently
in ADO? Or do I need to create this function in Access?
Thanks in advance.


Sub ExtractUniqueStylesByClass()
Dim cn As ADODB.Connection, RS As ADODB.Recordset, r As
Long
Dim Targetrange As Range
Dim intColIndex As Integer

Select Case TableXists("UNIQUESTYLESBYCLASS")
Case "TRUE"
DeleteAccessTable ("UNIQUESTYLESBYCLASS")
Case Else
End Select

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=K:\MPS\DATA\GMDATABASE.mdb;"
' open a recordset
Set RS = New ADODB.Recordset

'Create Table for Weekly Receipts By Class Report

SELECTOR = "SELECT RESVDATA.CLASS,(Left(RESVDATA.[MFG
STYLE],((InString(RESVDATA.[MFG STYLE],' * '))-1))) AS
STYLE INTO UNIQUESTYLESBYCLASS"

FROMCLAUSE = "FROM RESVDATA"

GROUPCLAUSE = "GROUP BY RESVDATA.CLASS, ((InStr(RESVDATA.
[MFG STYLE],' * '))-1)));"

strsql = SELECTOR & " " & FROMCLAUSE '& " " & GROUPCLAUSE

With RS
RS.Open strsql, cn, , , -1
End With

Set RS = Nothing
Set RS = New ADODB.Recordset

cn.Close
Set cn = Nothing

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with VBA InStr() function EagleOne Excel Discussion (Misc queries) 10 April 12th 07 02:47 PM
instr isn't finding all the matches Nate Oliver Excel Programming 1 February 26th 04 05:04 AM
instr isn't finding all the matches Bob Phillips[_6_] Excel Programming 2 February 25th 04 01:12 PM
Combine two macros using InStr? CLR Excel Programming 7 February 16th 04 02:57 AM
InStr used in SQL query dchow Excel Programming 3 July 21st 03 09:09 AM


All times are GMT +1. The time now is 09:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"