Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2003
    Location
    Virginia
    Posts
    10

    Exclamation Unanswered: New to VBScript and MS Access

    I know VB but I haven't used it in like 4 years. My problem is I haven't learned how to retrieve data from MS Access database using VBScript. Can someone please help!! It would be greatly appreciated. Thank you.

  2. #2
    Join Date
    Oct 2004
    Posts
    5

  3. #3
    Join Date
    Aug 2003
    Location
    Virginia
    Posts
    10
    Thank you Peter for your help. But unfortunately I cannot use the shortcut. I have to actually code it in notepad. Now if you know how to code it using VB that would be real helpful. I do apologize, I should have stated that on my first post. But once again thank you for your help.

  4. #4
    Join Date
    Feb 2003
    Location
    Wichita,KS
    Posts
    44
    Is this what you are looking for?
    Code:
    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordSet = CreateObject("ADODB.Recordset")
    
    objConnection.Open _
        "Provider = Microsoft.Jet.OLEDB.4.0; " & _
            "Data Source = hh.mdb" 
    
    objRecordSet.Open "SELECT * FROM States" , _
        objConnection, adOpenStatic, adLockOptimistic
    
    objRecordSet.MoveFirst
    
    Wscript.Echo "Number of records: " & objRecordset.RecordCount
    
    objRecordSet.Close
    objConnection.Close

  5. #5
    Join Date
    Aug 2003
    Location
    Virginia
    Posts
    10

    Red face

    Thank you I really appreciate your help!! I see where I went wrong but Do you know how to display the following in the command console?

    id fldMyVals

    -------------

    1 fee

    2 fie

    3 foe

    4 fum

  6. #6
    Join Date
    Feb 2003
    Location
    Wichita,KS
    Posts
    44
    I’m not too sure about that question. I guess you could use a Directory object to store the array then display it.
    Possibly something like this?
    Code:
    'Returns an array containing all the items in a Dictionary object
       Dim a, d, i, s   ' Create some variables.
       Set d = CreateObject("Scripting.Dictionary")
       d.Add "1", "fee"   ' Add some keys and items.
       d.Add "2", "fie"
       d.Add "3", "foe"
       d.Add "4", "fum"
       a = d.Items   ' Get the items.
       For i = 0 To d.Count -1 ' Iterate the array.
          s = s & a(i) & VbCrLf ' Create return string.
       Next
        Wscript.Echo s

Posting Permissions

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