Results 1 to 8 of 8

Thread: Adding indexes with VB code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    85

    Adding indexes with VB code

    If someone could help me out I would really appreciate it. I need to add 2 indexes to a table in an MS Access DB. I have to write a separate program that will check an (already existing) INI file to see if the indexes have already been added. If they haven't, I need to add the indexes, to the table, and edit the INI file so that it shows that the indexes have been added. One last question, since this program won't really need a GUI, is there a way I could create this program without using a form?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    You need something from which to run your code. You could set the visible property to false, unless of course, your code returned an error. I'd assume you would want to know what the error was, so then you could set visible to true. Anyway, thats your call.

    Here is some sample code to write to and read from, and InI file:
    VB Code:
    1. Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    2. Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    3. Private Sub Form_Load()
    4.     'KPD-Team 1999
    5.     'URL: [url]http://www.allapi.net/[/url]
    6.     'E-Mail: [email][email protected][/email]
    7.     Dim Ret As String, NC As Long
    8.     'Write the setting to the file (c:\test.ini) under
    9.     '   Project1 -> Keyname
    10.     WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
    11.     'Create a buffer
    12.     Ret = String(255, 0)
    13.     'Retrieve the string
    14.     NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    15.     'NC is the number of characters copied to the buffer
    16.     If NC <> 0 Then Ret = Left$(Ret, NC)
    17.     'Show our string
    18.     MsgBox Ret
    19.     'Delete the file
    20.     Kill "c:\test.ini"
    21. End Sub

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Re: Adding indexes with VB code

    Originally posted by PedroDePacos
    ... One last question, since this program won't really need a GUI, is there a way I could create this program without using a form?
    yes, u can remove the default form 1, then add a module.
    in the module create a sub called Main.
    Make Sub Main u'r startup routine (in the project properties... see picture)

    Add the code needed in Sub Main, and compile it.
    any errors can be shown using a msg box.





    -= a peet post =-

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    85
    Thanks alot for the help, it came in very handy. How about the code to add the indexes? Could you give me push in the right direction? Thanks Again!

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    yes, if u tell me a bit more about the indexes.
    -= a peet post =-

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    85
    I need to add 2 indexes to one table, both indexes are based on
    a different column. Is this the info you need?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    85
    Thanks for all your help, I figured it out and it works like a charm.
    This forum is the best and the help is unbelievable! I didn't even
    get this quality of help at college.

    Thanks Again!!!

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    glad u got i working there PedroDePacos, I logged off and went to bed (sory about that )
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width