แสดงบทความที่มีป้ายกำกับ R506 GIS แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ R506 GIS แสดงบทความทั้งหมด

วันอังคารที่ 20 กันยายน พ.ศ. 2554

VBA-Ms Access Delete Table

Function Del_Table()
Dim rst As Recordset
Dim table_name As String
DoCmd.SetWarnings False
Set rst = CurrentDb.OpenRecordset("SELECT * FROM disease")
Do While Not rst.EOF
codedz = rst.Fields("codedz")
table_name = "r506_" & codedz & "_village"

If TableExists(table_name) Then
    CurrentDb.TableDefs.Delete (table_name)
End If

rst.MoveNext
Loop

วันศุกร์ที่ 19 สิงหาคม พ.ศ. 2554

VBA-Ms Access Update_dolacode

Function update_dolacode()
Dim rsz As Recordset
Dim rst As Recordset
DoCmd.SetWarnings False
Set rsz = CurrentDb.OpenRecordset("SELECT * FROM amphoe WHERE dolacode<>amp_code")
Do While Not rsz.EOF

amp_code = rsz.Fields("amp_code")
dolacode = rsz.Fields("dolacode")

DoCmd.RunSQL "UPDATE EPE0 set ADDRCODE=Replace(ADDRCODE, '" & dolacode & "', '" & amp_code & "',1,4) WHERE left(ADDRCODE,4)='" & dolacode & "'"


rsz.MoveNext
Loop

End Function

วันเสาร์ที่ 2 กรกฎาคม พ.ศ. 2554

VBA-Ms Access Check TableExists

Function TableExists(TableName As String) As Boolean
'=================================================  ============================
' hlfUtils.TableExists
'-----------------------------------------------------------------------------
' Copyright by Heather L. Floyd - Floyd Innovations - www.floydinnovations.com
' Created 08-01-2005
'-----------------------------------------------------------------------------
' Purpose:  Checks to see whether the named table exists in the database
'-----------------------------------------------------------------------------
' Parameters:
' ARGUEMENT             :   DESCRIPTION
'-----------------------------------------------------------------------------
' TableName (String)    :   Name of table to check for
'-----------------------------------------------------------------------------
' Returns:  True, if table found in current db, False if not found.
'=================================================  ============================

Dim strTableNameCheck
On Error GoTo ErrorCode

'try to assign tablename value
strTableNameCheck = CurrentDb.TableDefs(TableName)

'If no error and we get to this line, true
TableExists = True

ExitCode:
    On Error Resume Next
    Exit Function

ErrorCode:
    Select Case Err.Number
        Case 3265  'Item not found in this collection
            TableExists = False
            Resume ExitCode
        Case Else
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "hlfUtils.TableExists"
            'Debug.Print "Error " & Err.number & ": " & Err.Description & "hlfUtils.TableExists"
            Resume ExitCode
    End Select

End Function

วันพุธที่ 22 มิถุนายน พ.ศ. 2554

VBA-Ms Access Create_Batfile


Function Create_Batfile()
Set fs = CreateObject("Scripting.FileSystemObject")
'Set a = fs.CreateTextFile("C:\Zr506\update.sql", True)
'a.writeline ("UPDATE  configuration SET last_date ='" & EngDate(Last_Date) & "';")
'a.Close
txtServer = "localhost"

Set a2 = fs.CreateTextFile("C:\Zr506\update.bat", True)
Set rsz = CurrentDb.OpenRecordset("SELECT * FROM disease ")
Do While Not rsz.EOF
codedz = rsz.Fields("codedz")
    a2.writeline ("" & Postgres_Path & "psql -d " & Postgres_DB & " -f C:\Zr506\sick_r506_" & codedz & ".sql  -U postgres  -h  " & txtServer & "")
    a2.writeline ("" & Postgres_Path & "psql -d " & Postgres_DB & " -f C:\Zr506\death_r506_" & codedz & ".sql  -U postgres  -h  " & txtServer & "")
   
rsz.MoveNext
Loop


a2.writeline ("" & Postgres_Path & "psql -d " & Postgres_DB & " -f C:\Zr506\update.sql -U postgres  -h  " & txtServer & "")
a2.Close
stAppName = "C:\Zr506\update.bat"  '¤Ø³µéͧà»ÅÕè¹ Drive áÅÐ Path ¤ÃѺ
Call Shell(stAppName, 3)
End Function

วันพุธที่ 8 มิถุนายน พ.ศ. 2554

VBA-Ms Access Import_Epe0

Function Import_Epe0(db_file)
If TableExists("EPE0") Then
    CurrentDb.TableDefs.Delete ("EPE0")
End If

DoCmd.TransferDatabase acImport, "Microsoft Access", "" & db_file & "", acTable, "epe0", "epe0", False
End Function