Jump to content

MS Access database - List of files


price98
 Share

Recommended Posts

Hi,

In Microsoft access, I created the database as shown below figure.In autoit, I have to create check boxes named as Controller,Simulator,Testing (as shown in figure). Suppose If I select testing check box then all related files to testing attribute  has to shown in database. Can anyone give any idea ?

Thanks

access.png

Link to comment
Share on other sites

Hi @FrancescoDiMuro,

Previously one of our friend helped in this code. At that time , I am doing only for desktop files. I don't know about ADO.

Thanks

#include <GUIConstantsEx.au3>
#include <File.au3>

Local $aFileList
Local $hGui = GUICreate("ProgramData", 450, 300)
Local $hButton_txt = GUICtrlCreateCheckbox("File list TXT", 144, 32, 97, 17)
Local $hButton_pdf = GUICtrlCreateCheckbox("File list PDF", 144, 62, 97, 17)
Local $hList = GUICtrlCreateList("", 10, 100, 430, 200)
GUISetState(@SW_SHOW)

$aFileList = _FileListToArray(@DesktopDir, "*.*", 1)  ; add your path here

While True
    $sMsg = GUIGetMsg()
    Switch $sMsg
        Case -3
            Exit
        Case $hButton_txt, $hButton_pdf
            $want_txt = IsChecked($hButton_txt)
            $want_pdf = IsChecked($hButton_pdf)
            GUICtrlSetData($hList, '')
            If $want_txt Or $want_pdf Then
               For $i = 1 To UBound($aFileList) - 1
                   $ext = StringLower(StringRight($aFileList[$i],4))
                   If ($want_txt And $ext == '.txt') Or _
                      ($want_pdf And $ext == '.pdf') Then
                       GUICtrlSetData($hList, $aFileList[$i])
                   EndIf
               Next
            EndIf
    EndSwitch
WEnd

Func IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc

 

Link to comment
Share on other sites

@price98 did you use my ADO.au3 UDF  ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 2 weeks later...

hi,

I done upto here. Can anyone tell me how to do from here?

#include <GUIConstantsEx.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GIVEN DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; File names
Global Const $File_1 = "Test.txt"
Global Const $File_2 = "Test2.txt"
Global Const $File_3 = "Test3.txt"
; Attribute names
Local Const $Attribute_1 = "Controller"
Local Const $Attribute_2 = "Simulator"
Local Const $Attribute_3 = "Testing"
; Files attributes
Global $File_1_Attr[3] = [$Attribute_1, $Attribute_2, $Attribute_3]
Global $File_2_Attr[3] = [$Attribute_3, "", ""]
Global $File_3_Attr[3] = ["", $Attribute_1, ""]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI FORM EXAMPLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Form_Main = GUICreate("GUI managing Database", 250, 380)
$Group_Attributes = GUICtrlCreateGroup("Attributes", 20, 20, 200, 130)
$Checkbox_1 = GUICtrlCreateCheckbox($Attribute_1, 40, 50)
$Checkbox_2 = GUICtrlCreateCheckbox($Attribute_2, 40, 80)
$Checkbox_3 = GUICtrlCreateCheckbox($Attribute_3, 40, 110)
$Group_Files = GUICtrlCreateGroup("Files", 20, 160, 200, 200)
$Label_1 = GUICtrlCreateLabel("", 40, 180, 150, 20)
$Label_2 = GUICtrlCreateLabel("", 40, 220, 150, 20)
$Label_3 = GUICtrlCreateLabel("", 40, 260, 150, 20)
GUISetState(@SW_SHOW)
; Files variablies
Global $File_1_Content = ""
Global $File_2_Content = ""
Global $File_3_Content = ""
Global $File_1_Access = False
Global $File_2_Access = False
Global $File_3_Access = False
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PROGRAM BODY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Files content read
    If Not File_read($File_1) Or Not File_read($File_2) Or Not File_read($File_3) Then
        Exit
    EndIf
; Endless loop
While 1
    ; Checkbox status changed
    $msg = GUIGetMsg()
    Switch $msg
        Case $Checkbox_1, $Checkbox_2, $Checkbox_3
            $File_1_Access = False
            $File_2_Access = False
            $File_3_Access = False
            Access($Checkbox_1)
            Access($Checkbox_2)
            Access($Checkbox_3)
            ; Files show
            If $File_1_Access Then
                GUICtrlSetData($Label_1, $File_1_Content)
            Else
                GUICtrlSetData($Label_1, "")    
            EndIf
            If $File_2_Access Then
                GUICtrlSetData($Label_2, $File_2_Content)
            Else
                GUICtrlSetData($Label_2, "")    
            EndIf
            If $File_3_Access Then
                GUICtrlSetData($Label_3, $File_3_Content)
            Else
                GUICtrlSetData($Label_3, "")    
            EndIf
        Case $GUI_EVENT_CLOSE ; Close GUI
            ExitLoop
    EndSwitch
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func File_read($Filename)
    Local $hFileOpen = FileOpen($Filename, $FO_READ)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file " & $Filename)
        Return False
    EndIf
    Switch $Filename
        Case $File_1
            $File_1_Content = FileRead($hFileOpen)
        Case $File_2
            $File_2_Content = FileRead($hFileOpen)
        Case $File_3
            $File_3_Content = FileRead($hFileOpen)
    EndSwitch
    FileClose($hFileOpen)
    Return True
EndFunc
;
Func Access($Checkbox)
    If GUICtrlRead($Checkbox) = $GUI_CHECKED Then
        For $vElement In $File_1_Attr
            If $vElement = GUICtrlRead($Checkbox, $GUI_READ_EXTENDED) Then
                $File_1_Access = True
            EndIF
        Next
        For $vElement In $File_2_Attr
            If $vElement = GUICtrlRead($Checkbox, $GUI_READ_EXTENDED) Then
                $File_2_Access = True
            EndIF
        Next
        For $vElement In $File_3_Attr
            If $vElement = GUICtrlRead($Checkbox, $GUI_READ_EXTENDED) Then
                $File_3_Access = True
            EndIF
        Next
    EndIF
EndFunc

 

Link to comment
Share on other sites

hi,

I done upto here. Here I done for 3 files(static), If i have to do infinity number of files(dynamically). How to do?

And after clicking controller checkbox, How to list the files?

Can anyone help me?

Thanks

#include <GUIConstantsEx.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DB DATA ;;;;;;;;;;;;;;;;;;:::;;;;;;;;;;;;;;;;
Local $DB_Name = "Database4.accdb"
Local $Table_Name = "bhanu"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VARIABLES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; File names
Global $Files[3] = ["", "", ""]
; Files attributes
Global $File_Attr[3][3]
; Attribute names
Local $Attr_Name[3] = ["", "", ""]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PROGRAM BODY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DB read
$AdoCon = ObjCreate("ADODB.Connection")
$AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name)
For $i = 0 To 2 Step 1
    $AdoRs = ObjCreate("ADODB.Recordset")
    $AdoRs.CursorType = 1
    $AdoRs.LockType = 3
    $AdoRs.Open("SELECT * FROM " & $Table_Name & " WHERE ID = " & ($i + 1), $AdoCon)
    $Files[$i] = $AdoRs.Fields(1).Value
    $File_Attr[$i][0] = $AdoRs.Fields(2).Value
    $File_Attr[$i][1] = $AdoRs.Fields(3).Value
    $File_Attr[$i][2] = $AdoRs.Fields(4).Value
Next
$AdoCon.Close
; Attributes implode
Local $a = 0
For $i = 0 To 2 Step 1
    For $j = 0 To 2 Step 1
        If $a < 3 And Not $File_Attr[$i][$j] = "" Then
            For $k = $a To 2 Step 1
                If $Attr_Name[$k] = $File_Attr[$i][$j] Then
                    ContinueLoop 2
                EndIf
            Next
            $Attr_Name[$a] = $File_Attr[$i][$j]
            $a = $a + 1
        EndIf
    Next
Next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI FORM EXAMPLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Form_Main = GUICreate("GUI managing Database", 250, 380)
$Group_Attributes = GUICtrlCreateGroup("Attributes", 20, 20, 200, 130)
$Checkbox_1 = GUICtrlCreateCheckbox($Attr_Name[0], 40, 50)
$Checkbox_2 = GUICtrlCreateCheckbox($Attr_Name[1], 40, 80)
$Checkbox_3 = GUICtrlCreateCheckbox($Attr_Name[2], 40, 110)
$Group_Files = GUICtrlCreateGroup("Files", 20, 160, 200, 200)
$Label_1 = GUICtrlCreateLabel("", 40, 180, 100, 20)
$Label_2 = GUICtrlCreateLabel("", 40, 220, 100, 20)
$Label_3 = GUICtrlCreateLabel("", 40, 260, 100, 20)
GUISetState(@SW_SHOW)
; GUI loop
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Checkbox_1, $Checkbox_2, $Checkbox_3
            GUICtrlSetData($Label_1, "")
            GUICtrlSetData($Label_2, "")
            GUICtrlSetData($Label_3, "")
            Access($Checkbox_1)
            Access($Checkbox_2)
            Access($Checkbox_3)
        Case $GUI_EVENT_CLOSE ; Close GUI
            ExitLoop
    EndSwitch
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNCTION ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func Access($Checkbox)
    If GUICtrlRead($Checkbox) = $GUI_CHECKED Then
        Local $Chkbox_label = GUICtrlRead($Checkbox, 1)
        If $File_Attr[0][0] = $Chkbox_label Or $File_Attr[0][1] = $Chkbox_label Or $File_Attr[0][2] = $Chkbox_label Then
            GUICtrlSetData($Label_1, $Files[0])
        EndIF
        If $File_Attr[1][0] = $Chkbox_label Or $File_Attr[1][1] = $Chkbox_label Or $File_Attr[1][2] = $Chkbox_label Then
            GUICtrlSetData($Label_2, $Files[1])
        EndIF
        If $File_Attr[2][0] = $Chkbox_label Or $File_Attr[2][1] = $Chkbox_label Or $File_Attr[2][2] = $Chkbox_label Then
            GUICtrlSetData($Label_3, $Files[2])
        EndIF
    EndIF
EndFunc

 

Database4.accdb

Link to comment
Share on other sites

On 1/10/2018 at 1:19 PM, price98 said:

If i have to do infinity number of files(dynamically). How to do?

_FileListToArray() or _FileListToArrayRec().

On 1/10/2018 at 1:19 PM, price98 said:

And after clicking controller checkbox, How to list the files?

Check the state of the checkbox, and do an action only if it is $GUI_CHECKED; there are a tons of examples on the Forum :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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...