AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

EZ Question- Retrieving MDB Records using an Array + Com.ahk

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
iyerushalmi



Joined: 24 Dec 2009
Posts: 5

PostPosted: Thu Dec 24, 2009 2:57 am    Post subject: EZ Question- Retrieving MDB Records using an Array + Com.ahk Reply with quote

I am making an AHK to create/edit/delete records in a Microsoft Access Database. I am new to AHK and have a question.

I am writing a library of functions to call upon when working with the database. I would like the function below to store the retrieved record into an array for easy access to all fields in that record.

Currently everything is simply stored into one variable: sData. Can anyone please help? It would be greatly appreciated!

Code:
GetProduct(SKU) {
   sSource  := "SELECT * FROM " . "Products" . " WHERE SKU = '" . SKU . "'"
   sConnect := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" . "C:\Documents and Settings\TheBeadChest.com\Desktop\scripts\addtoinv\Inventory.mdb"

   COM_Init()
   prs :=   COM_CreateObject("ADODB.Recordset")
   COM_Invoke(prs, "Open", sSource, sConnect)
   Loop
   {
      If   COM_Invoke(prs, "EOF")
        Break
      pFields   := COM_Invoke(prs, "Fields")
      Loop, %   COM_Invoke(pFields, "Count")
        pField:= COM_Invoke(pFields, "Item", A_Index-1)
      ,   sData .= COM_Invoke(pField, "Name") . ": " . COM_Invoke(pField, "Value") . "`r`n"
      ,   COM_Release(pField)
      COM_Release(pFields)
      COM_Invoke(prs, "MoveNext")
   }
   COM_Invoke(prs, "Close")
   COM_Release(prs)
   COM_Term()
}
Back to top
View user's profile Send private message
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Sun Dec 27, 2009 9:27 am    Post subject: Re: EZ Question- Retrieving MDB Records using an Array + Com Reply with quote

try this:

Code:
sField%A_Index% := COM_Invoke(pField, "Name") . ": " . COM_Invoke(pField, "Value")
sName%A_Index% := COM_Invoke(pField, "Name")
sValue%A_Index% := COM_Invoke(pField, "Value")


Hubert
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Mon Dec 28, 2009 1:57 pm    Post subject: Reply with quote

FYI if you want to work with true arrays you should take a look into AutoHotkey_L.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group