Jump to content

Using Querys in Access.au3


Hufo1910
 Share

Recommended Posts

Hey everybody,

i try to use the AutoIT Access.au3 & Example_Access.au3 => (https://www.autoitscript.com/forum/topic/140277-ms-access-udf/) conected with Access 2013 DB (64bit, W10).
Most _funcs work as they should, but I dont know how to send querys to Access.
At the moment i know how to show data by using

Func Example_AccessSelectQueryFetch ()
    Local $o_DataBase = _AccessOpen(@ScriptDir & "\Test.mdb")
    Local $h_Query, $aRow [1]

    If $o_DataBase = 0 Then
        MsgBox(0, "Information", "Database file is not found :-" & @CR & @ScriptDir & "\Test.mdb")
        Return
    EndIf

    ;Local $feedback =_AccessSelectQuery ($o_DataBase, "Select * From  tblTable1  where  fld1=3"  )
    Local $feedback =_AccessSelectQuery ($o_DataBase, "Select * From  tblTable1", $h_Query )          ; <<======

    if $feedback = 0 Then
        MsgBox (0,0, _AccessErrCode() & " " & _AccessErrMsg ())
        _AccessClose($o_DataBase)
        Return
    EndIf

    while _AccessFetchData ( $h_Query, $aRow) = 1
        _ArrayDisplay ($aRow)
        If _AccessRecordMove($h_Query, 1) = 0 Then ExitLoop
    WEnd
    MsgBox (0,"Info", "All Rec. in Query is read" & @LF & _AccessErrCode() & " " & _AccessErrMsg () )

    _AccessClose($o_DataBase)
EndFunc

I would like to replace "Select * From tblTable1"  by something like

SELECT fld1              
FROM tblTable1
WHERE fld2 = 99 ;
   (<== works in Access SQL)

If i do it like this

Local $feedback =_AccessSelectQuery ($o_DataBase, "SELECT fld1 FROM  tblTable1 WHERE fld2 = 99", $h_Query)

it doesnt work.
Does anybody know what i am doing wrong ?
Is

_AccessSelectQueryFetch

the correct _func for using a sort / filter function or is

Func Example_AccessActionQuery()
    Local $o_DataBase = _AccessOpen(@ScriptDir & "\Test.mdb")
    Local $h_Query

    If $o_DataBase = 0 Then
        MsgBox(0, "Information", "Database file is not found :-" & @CR & @ScriptDir & "\Test.mdb")
        Return
    EndIf

    Local $feedback =_AccessActionQuery ($o_DataBase, "INSERT INTO tblTable1 ( fld1, fld2 ) values ('Try add rec', 5)"  )
    if $feedback = 0 Then
        MsgBox (0,0, _AccessErrCode() & " " & _AccessErrMsg ())
    Else
        MsgBox (16,"Info",  "Done without Errors")
    EndIf

    _AccessClose($o_DataBase)
EndFunc

the better choice (or maybe anything else) ?
Maybe there is only a syntax mistake or the .udf doesnt work with Access 2013 at all ?

Thanks for your support: Hufo
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...