PC Review


Reply
Thread Tools Rate Thread

CREATE INDEX Multiple Variables SQL

 
 
Jerad via AccessMonster.com
Guest
Posts: n/a
 
      24th Mar 2006
Okay, heres my Problem. I need to create indexes on multiple fields in
multiple tables. These fields and table names are static, but i'd like to use
my variables for table names and field names in the SQL statement. Heres my
code, so far

Public Sub tryIndexing()
Dim sqlDeal As String
Dim strFieldName As String
Dim strTableName As String

strTableName = "tableOne"
strFieldName = "fieldOne"

sqlDeal = "CREATE INDEX " & strFieldName & " on " & strTableName & "(" &
strFieldName & ");"
DoCmd.RunSQL (sqlDeal)
End Sub

Now i need to create index for fieldTwo and fieldThree and then (tableTwo,
fieldOne and FieldTwo Ect.)
Im not sure how to go about looping this to change these variables each loop.
Any help appreciated,
Thanks in advance.
Jerad

--
Jerad

Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      24th Mar 2006
Are you also saying that tableOne and tableTwo will have the same fields in
them? That sounds extremely unusual, and is probably indicative of a
database that isn't properly normalized.

As well, are you saying that you want an index on fieldTwo in tableOne and
an index on fieldThree, or that you want one index that contains both
fields?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Jerad via AccessMonster.com" <u17799@uwe> wrote in message
news:5dbd2f5eb46da@uwe...
> Okay, heres my Problem. I need to create indexes on multiple fields in
> multiple tables. These fields and table names are static, but i'd like to
> use
> my variables for table names and field names in the SQL statement. Heres
> my
> code, so far
>
> Public Sub tryIndexing()
> Dim sqlDeal As String
> Dim strFieldName As String
> Dim strTableName As String
>
> strTableName = "tableOne"
> strFieldName = "fieldOne"
>
> sqlDeal = "CREATE INDEX " & strFieldName & " on " & strTableName & "(" &
> strFieldName & ");"
> DoCmd.RunSQL (sqlDeal)
> End Sub
>
> Now i need to create index for fieldTwo and fieldThree and then (tableTwo,
> fieldOne and FieldTwo Ect.)
> Im not sure how to go about looping this to change these variables each
> loop.
> Any help appreciated,
> Thanks in advance.
> Jerad
>
> --
> Jerad
>
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
Jerad via AccessMonster.com
Guest
Posts: n/a
 
      24th Mar 2006
Douglas,
Thanks for the speedy response.
Sorry if I was confusing, the field names are NOT the same in the seperate
tables, i was just using the names as generic example. I need an index for
fieldOne and fieldTwo on table1, and then for Table2 I need indexes for
anotherField1 and anotherfield2. Basicly, instead of repeating the sql
statement :

strTableName = "tblInventory"
strFieldName = "DE_CAT1_PART"
sqlDeal = "CREATE INDEX " & strFieldName & " on " & strTableName & "(" &
strFieldName & ");"
DoCmd.RunSQL (sqlDeal)

Over and over, changing the variable strings each time( id have like 5 pages
of repetative code just with different table names and fields). Id like for
it to loop, and change the strings in the variable to specific pre defined
field names. let me know if that helps.
Thanks again,
Jerad



Douglas J. Steele wrote:
>Are you also saying that tableOne and tableTwo will have the same fields in
>them? That sounds extremely unusual, and is probably indicative of a
>database that isn't properly normalized.
>
>As well, are you saying that you want an index on fieldTwo in tableOne and
>an index on fieldThree, or that you want one index that contains both
>fields?
>
>> Okay, heres my Problem. I need to create indexes on multiple fields in
>> multiple tables. These fields and table names are static, but i'd like to

>[quoted text clipped - 23 lines]
>> Thanks in advance.
>> Jerad


--
Jerad

Message posted via http://www.accessmonster.com
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      24th Mar 2006
Where are you going to get the Table and Field names from?

What you're trying to do is certainly possible, but how you do it all
depends on how you are going to provide the values.

For example, you could have two tables: one containing the names of the
tables you want to do this for, and the other containing the names of the
fields you want to create indexes on (linked to the first table). You could
then have code like the following untested air-code:

Dim dbCurr As DAO.Database
Dim rsTables As DAO.Recordset
Dim rsFields As DAO.Recordset

Set dbCurr = CurrentDB()
Set rsTables = dbCurr.OpenRecordset("SELECT TableName From Tables")
Do While rsTables.EOF = False
strTableName = rsTables!TableName
Set rsFields = dbCurr.OpenRecordset("SELECT FieldName FROM Fields " &
_
"WHERE TableName = '[" & strTableName & "]'")
Do While rsFields.EOF = False
strFieldName = rsFields!FieldName
sqlDeal = "CREATE INDEX " & strFieldName & _
" on " & strTableName & "(" & strFieldName & ");"
dbCurr.Execute sqlDeal
rsFields.MoveNext
Loop
rsTables.MoveNext
Loop

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Jerad via AccessMonster.com" <u17799@uwe> wrote in message
news:5dbe8cb5c9c44@uwe...
> Douglas,
> Thanks for the speedy response.
> Sorry if I was confusing, the field names are NOT the same in the seperate
> tables, i was just using the names as generic example. I need an index for
> fieldOne and fieldTwo on table1, and then for Table2 I need indexes for
> anotherField1 and anotherfield2. Basicly, instead of repeating the sql
> statement :
>
> strTableName = "tblInventory"
> strFieldName = "DE_CAT1_PART"
> sqlDeal = "CREATE INDEX " & strFieldName & " on " & strTableName & "(" &
> strFieldName & ");"
> DoCmd.RunSQL (sqlDeal)
>
> Over and over, changing the variable strings each time( id have like 5
> pages
> of repetative code just with different table names and fields). Id like
> for
> it to loop, and change the strings in the variable to specific pre defined
> field names. let me know if that helps.
> Thanks again,
> Jerad
>
>
>
> Douglas J. Steele wrote:
>>Are you also saying that tableOne and tableTwo will have the same fields
>>in
>>them? That sounds extremely unusual, and is probably indicative of a
>>database that isn't properly normalized.
>>
>>As well, are you saying that you want an index on fieldTwo in tableOne and
>>an index on fieldThree, or that you want one index that contains both
>>fields?
>>
>>> Okay, heres my Problem. I need to create indexes on multiple fields in
>>> multiple tables. These fields and table names are static, but i'd like
>>> to

>>[quoted text clipped - 23 lines]
>>> Thanks in advance.
>>> Jerad

>
> --
> Jerad
>
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Multiple Index NEWER USER Microsoft Access VBA Modules 1 28th Mar 2010 04:56 AM
Can I create a single index from multiple files? James Microsoft Word Document Management 5 7th Aug 2009 09:20 PM
How do I create an index for multiple word documents? dbfpuc Microsoft Word Document Management 5 23rd Jan 2008 09:45 AM
Index Match function for multiple linked variables Bob Microsoft Excel Worksheet Functions 13 23rd Nov 2005 12:56 AM
Index Match function for multiple linked variables Bob Microsoft Excel Worksheet Functions 0 22nd Nov 2005 02:12 AM


Features
 

Advertising
 

Newsgroups
 


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