แสดงกระทู้

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Earth

หน้า: [1] 2
1
สอบถามสร้างคิวรี่โดย ฟิลด์วันหมดอายุปกติค่าจะมี 01012019(8หลัก)
เงื่อนไขคือ ถ้าไม่ครบ8หลัก ให้เติม0ด้านหน้า
เช่น 1012019 ==> เป็น 01012019 ค่ะ

2
ห้อง MS Access / สอบถามErrorค่ะ
« เมื่อ: 03 ก.ย. 62 , 10:48:09 »
สอบถามเออเร่อแสดงแบบนี้ค่ะ
หาสาเหตุไม่ได้ แต่สังเกตว่าเกิดในฟอร์มที่แสดงQueryค่ะ
เพราะนำโค้ดกับปุ่มเดียวกัน ไปสร้างอีกฟอร์มเปล่าๆ สามารถรันได้ปกติค่ะ


3
ห้อง MS Access / สลับตำแหน่งText ในQuery
« เมื่อ: 02 ก.ย. 62 , 16:30:30 »

สอบถามค่ะ ฟิลด์LOTแสดง  20190821
ต้องการสลับตำแหน่งเป็น  21082019

สอบถามการสร้างในQueryค่ะ
ตอนนั้นลองใช้ Right([Lot],4) & Left([Lot],4) ผลลัพธ์เป็น 08212019

รบกวนอาจารย์ผู้รู้ด้วยนะคะ

4
ห้อง MS Access / สร้างปุ่มimport txt.file
« เมื่อ: 02 ก.ย. 62 , 15:39:36 »
สอบถามErrorที่เกิดจากสร้างปุ่มimport txt fileค่ะ



สอบถามเออเร่อเกิดจากอะไรคะ โค้ดที่สร้างในModuleตามนี้ค่ะ
รบกวนช่วยหน่อยนะคะ (ห่างหายจากการเขียนไปนานเลยค่ะTT)
โค๊ด: [Select]
Option Compare Database

Option Explicit

'***************** Code Start **************
'This code was originally written by Ken Getz.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
' Code courtesy of:
'   Microsoft Access 95 How-To
' Ken Getz and Paul Litwin
' Waite Group Press, 1996

Type tagOPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    strFilter As String
    strCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    strFile As String
    nMaxFile As Long
    strFileTitle As String
    nMaxFileTitle As Long
    strInitialDir As String
    strTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    strDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long

Global Const ahtOFN_READONLY = &H1
Global Const ahtOFN_OVERWRITEPROMPT = &H2
Global Const ahtOFN_HIDEREADONLY = &H4
Global Const ahtOFN_NOCHANGEDIR = &H8
Global Const ahtOFN_SHOWHELP = &H10
' You won't use these.
'Global Const ahtOFN_ENABLEHOOK = &H20
'Global Const ahtOFN_ENABLETEMPLATE = &H40
'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
Global Const ahtOFN_NOVALIDATE = &H100
Global Const ahtOFN_ALLOWMULTISELECT = &H200
Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
Global Const ahtOFN_PATHMUSTEXIST = &H800
Global Const ahtOFN_FILEMUSTEXIST = &H1000
Global Const ahtOFN_CREATEPROMPT = &H2000
Global Const ahtOFN_SHAREAWARE = &H4000
Global Const ahtOFN_NOREADONLYRETURN = &H8000
Global Const ahtOFN_NOTESTFILECREATE = &H10000
Global Const ahtOFN_NONETWORKBUTTON = &H20000
Global Const ahtOFN_NOLONGNAMES = &H40000
' New for Windows 95
Global Const ahtOFN_EXPLORER = &H80000
Global Const ahtOFN_NODEREFERENCELINKS = &H100000
Global Const ahtOFN_LONGNAMES = &H200000


Function GetOpenFile(Optional varDirectory As Variant, Optional varTitleForDialog As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
    lngFlags = ahtOFN_FILEMUSTEXIST Or ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
    If IsMissing(varDirectory) Then
        varDirectory = ""
    End If
    If IsMissing(varTitleForDialog) Then
        varTitleForDialog = "Please choose a Target File ..."
    End If

    ' Define the filter string and allocate space in the "c"
    ' string Duplicate this line with changes as necessary for
    ' more file templates.
    strFilter = ahtAddFilterItem(strFilter, "All File (*.*)", "*.*")               '   "Access (*.mdb)", "*.MDB")
    ' Now actually call to get the file name.
    varFileName = ahtCommonFileOpenSave(OpenFile:=True, InitialDir:=varDirectory, Filter:=strFilter, flags:=lngFlags, _
                    DialogTitle:=varTitleForDialog)
    If Not IsNull(varFileName) Then
        varFileName = TrimNull(varFileName)
    End If
    GetOpenFile = varFileName
End Function


Function ahtAddFilterItem(strFilter As String, _
    strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases"), a null character, the skeleton
' (like "*.mdb;*.mda") and a final null character.

    If IsMissing(varItem) Then varItem = "*.*"
    ahtAddFilterItem = strFilter & _
               strDescription & vbNullChar & _
               varItem & vbNullChar
End Function

Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
    intPos = InStr(strItem, vbNullChar)
    If intPos > 0 Then
        TrimNull = Left(strItem, intPos - 1)
    Else
        TrimNull = strItem
    End If
End Function
'************** Code End *****************

Function ahtCommonFileOpenSave( _
            Optional ByRef flags As Variant, _
            Optional ByVal InitialDir As Variant, _
            Optional ByVal Filter As Variant, _
            Optional ByVal FilterIndex As Variant, _
            Optional ByVal DefaultExt As Variant, _
            Optional ByVal FileName As Variant, _
            Optional ByVal DialogTitle As Variant, _
            Optional ByVal hwnd As Variant, _
            Optional ByVal OpenFile As Variant) As Variant
' This is the entry point you'll use to call the common
' file open/save dialog. The parameters are listed
' below, and all are optional.
'
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem. See examples.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Open File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFileName As String
Dim strFileTitle As String
Dim fResult As Boolean
    ' Give the dialog a caption title.
    If IsMissing(InitialDir) Then InitialDir = CurDir
    If IsMissing(Filter) Then Filter = ""
    If IsMissing(FilterIndex) Then FilterIndex = 1
    If IsMissing(flags) Then flags = 0&
    If IsMissing(DefaultExt) Then DefaultExt = ""
    If IsMissing(FileName) Then FileName = ""
    If IsMissing(DialogTitle) Then DialogTitle = ""
    If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp
    If IsMissing(OpenFile) Then OpenFile = True
    ' Allocate string space for the returned strings.
    strFileName = Left(FileName & String(256, 0), 256)
    strFileTitle = String(256, 0)
    ' Set up the data structure before you call the function
    With OFN
        .lStructSize = Len(OFN)
        .hwndOwner = hwnd
        .strFilter = Filter
        .nFilterIndex = FilterIndex
        .strFile = strFileName
        .nMaxFile = Len(strFileName)
        .strFileTitle = strFileTitle
        .nMaxFileTitle = Len(strFileTitle)
        .strTitle = DialogTitle
        .flags = flags
        .strDefExt = DefaultExt
        .strInitialDir = InitialDir
        ' Didn't think most people would want to deal with
        ' these options.
        .hInstance = 0
        '.strCustomFilter = ""
        '.nMaxCustFilter = 0
        .lpfnHook = 0
        'New for NT 4.0
        .strCustomFilter = String(255, 0)
        .nMaxCustFilter = 255
    End With
    ' This will pass the desired data structure to the
    ' Windows API, which will in turn it uses to display
    ' the Open/Save As Dialog.
    If OpenFile Then
        fResult = aht_apiGetOpenFileName(OFN)
    Else
        fResult = aht_apiGetSaveFileName(OFN)
    End If

    ' The function call filled in the strFileTitle member
    ' of the structure. You'll have to write special code
    ' to retrieve that if you're interested.
    If fResult Then
        ' You might care to check the Flags member of the
        ' structure to get information about the chosen file.
        ' In this example, if you bothered to pass in a
        ' value for Flags, we'll fill it in with the outgoing
        ' Flags value.
        If Not IsMissing(flags) Then flags = OFN.flags
        ahtCommonFileOpenSave = TrimNull(OFN.strFile)
    Else
        ahtCommonFileOpenSave = vbNullString
    End If
End Function


ส่วนโค้ดที่ปุ่มimportตามนี้นะคะ
โค๊ด: [Select]
Option Compare Database

Private Sub Command8_Click()
Me.txt_FilePath = ""
Dim s As String
    If IsNull(txt_FilePath) Or txt_FilePath = "" Then
        s = GetOpenFile("D:\")
    Else
        s = GetOpenFile(Me.txt_FilePath)
    End If
    If s = "" Then
    Else
        If Dir(s) = "" Then
            Beep
            MsgBox "????????? " & s
        Else
            txt_FilePath = s
                    CurrentDb.Execute "DELETE FROM Donki_Receiving", dbFailOnError
                txt_FilePath.BackColor = RGB(255, 204, 0)
                Application.DoCmd.TransferText acImportDelim, "Donki_Receiving", "Donki_Receiving", (txt_FilePath), True
                Me.txt_FilePath = ""

        End If
    End If
Exit Sub
End Sub


5

ต้องการคิวรี่ข้อมูลจากหน้าฟอร์ม ค้นหารายการจากTextbox วันที่.... ถึงวันที่.... และเงื่อนไขฟิลด์อื่นๆ
รบกวนขอแนวทางหน่อยค่ะ

ตัวอย่างฟอร์ม

6
ห้อง MS Access / สอบถามError import csv fileค่ะ
« เมื่อ: 15 ม.ค. 62 , 11:29:27 »
สอบถามค่ะ Errorนี้เกิดจากอะไรคะ
สร้างปุ่มimportไฟล์ CSVค่ะ ลองเทสดูแล้วErrorค่ะ


7
สอบถามError ที่เกิดจากการimportไฟล์ CSVค่ะ
คือเมื่อimport ไฟล์ CSV ในรูปแบบ .accdb สามารถimportเข้ามาได้ปกติไม่มีError
แต่พอSAVEไฟล์เป็น .accde แล้วimportไฟล์ CSVเดิม กลับขึ้นErrorตามรูปด้านล่างนี้ค่ะ

อยากทราบว่าเกิดจากอะไรคะ






8
สอบถามQuery เพื่อให้ได้ข้อมูลที่แสดงวันที่(ทุกวัน)ของ1เดือน  ผลลัพธ์ตารางที่ได้คือ



จากQueryด้านบนต้องการนำมาเพิ่มวันที่ที่ไม่มีในข้อมูลนี้ให้ครบ1เดือนตามรูปนี้ค่ะ
จากรูปวันที่ไม่มีข้อมูล Takein Take outจะแสดงวันที่ด้วย เป็นค่าว่าง  (ค่าที่เพิ่มในกรอบแดง)
ส่วนค่า Balance แถวแรกมาจากยอดยกมา
ค่า Balance ถัดมามาจากค่าBalance ก่อนหน้า + Takein(วันปัจจุบัน) - TakeOut(วันปัจจุบัน)ค่ะ


9
สอบถามการQuery Append โดยกรองเงื่อนไขตามComboboxค่ะ
จากกระทู้ https://www.thai-access.com/index.php?topic=196.msg609#msg609 ได้กรองข้อมูลจากQuery มาแสดง

แต่ในกระทู้นี้ในQueryชื่อว่า "StockCard"เพิ่มฟิลด์Remark และทำการAppend Query ไปไว้ในตาราง StockDaily
โดยกรองค่าในฟิลด์ Type OF GOODS ที่Comboboxในหน้าฟอร์มImportFrm ตามรูป



โค้ดในปุ่มViewในหน้าฟอร์ม ImportFrmคือ

โค๊ด: [Select]
CurrentDb.Execute "DELETE FROM StockDaily", dbFailOnError

If Type_cmb = "All" Then
Type_cmb = "*"

'Run Query
On Error GoTo PROC_ERR
  DoCmd.SetWarnings False
  DoCmd.OpenQuery "StockCard"
  DoCmd.SetWarnings True
PROC_ERR:
  DoCmd.SetWarnings True
DoCmd.Close acForm, "ViewStockCard"
DoCmd.OpenForm "ViewStockCard"

Else
DoCmd.OpenForm "ViewStockCard"
End If

และนี่คือหน้าตาฟอร์มที่กรองค่าจากCombobox



ปัญหาคือข้อมูลไม่ได้กรองให้ค่ะ แต่แสดงทั้งหมดแทน
ปล. จากกระทู้เดิมที่ทำสามารถกรองค่าได้ตามข้อมูลนี้เลยค่ะ แต่แค่เอามาปรับแก้ทำAppend Queryเพิ่มขึ้นค่ะ

10
ห้อง MS Access / สร้าง QR Code
« เมื่อ: 15 พ.ค. 61 , 09:48:22 »
สอบถามค่ะ

อยากทราบว่า Access สามารถนำข้อมูลจากตาราง มาสร้างQRCode ในReportได้ยังไงบ้างคะ

11
สวัสดีค่ะ
สอบถามวิธี การเก็บค่าInputตามDigitที่กำหนดไว้เพื่อนำไปทำQR Codeค่ะ
ตามรูปด้านล่างนี้

อธิบาย>>>

หน้าฟอร์มมีTextboxทั้งหมด 3กล่อง สำหรับInputค่า โดยมาจากตารางที่เก็บค่าคือ
ItemID >> Field size = 10
Name  >> Field size = 20
Lot >> Field size = 10
ต้องการให้inputค่ากี่Digit จะไปเก็บลงอีกTable เท่ากับDigitที่กำหนดไว้ค่ะ
เช่น ItemID >> Field size = 10 กรอกมาแค่ A0001 (5ตัว) ค่าที่ไปเก็บในอีกTableคือ A0001เคาะเคาะเคาะเคาะเคาะ ประมานนี้ค่ะ

12
ห้อง MS Access / Error "The database engine could not lock table"
« เมื่อ: 08 พ.ค. 61 , 15:43:53 »
ตอนรัน Queryขึ้นแจ้งเตือนดังรูปด้านล่าง ซึ่งไม่ได้เปิด Tableดังกล่าว หรือTableใด รวมถึงไม่มีการเปิดฟอร์ม Reportใดๆไว้เลยค่ะ
ในแต่ตอนรันครั้งแรก ระบบเอาข้อมูลจากตารางMonthly_FG ไปใช้ต่ออีกหลายQuery
คิดว่าน่าจะมีProcess ค้างอยู่ แต่ไม่รู้ตรงไหน
เวลาจะรันครั้งที่สอง จึงต้องปิดและเปิดโปรแกรมใหม่ถึงจะสามารถรันได้ปกติ

อยากทราบว่ามีวิธีไหนที่จะเขียนโค้ดดักก่อนว่า ให้เคลียร์หรือปิดProcessทั้งหมดก่อน หรือปิดและเปิดโปรแกรมใหม่ไหมคะ
เพื่อจะได้ไม่มีErrorแบบนี้เกิดขึ้น



13
จากรูปต้องการให้กรองค่าตรงMake tableค่ะ
ต้องการกรองทั้งหมดของType2 โดยที่เงื่อนไขคือType2ต้องไม่เท่ากับค่าในตารางNot_FG ค่ะ

14
ห้อง MS Access / ข้อมูลเปลี่ยนตอนกดPrint
« เมื่อ: 03 พ.ค. 61 , 11:34:10 »
สอบถามการแสดงข้อมูลหน้าForm1
โดยค่าของ Takein เอาค่ามาจากSubReportของ StockMonthly_FG_Query_SUM มาวางและ Visibleซ่อนฟอร์มนั้นไว้
ดึงค่ามาแบบนี้
=[Forms]![Form1]![StockMonthly_FG_Query_SUM]![Text35]

เวลาแสดงข้อมูลสามารถแสดงได้ปกติ แต่พอกดปุ่มปริ้น โดยใช้โค้ด DoCmd.OpenForm "Form1", acPreview
ทำไมข้อมูลที่วงสีแดงตามรูปด้านล่างเปลี่ยนไปคะ
และExport เป็นPDFออกมาก็เปลี่ยนด้วยค่ะ


15
ห้อง MS Access / Sumค่า Grand Total ใน Report Footer
« เมื่อ: 26 เม.ย. 61 , 11:27:01 »
จากรูปต้องการหาค่า Grand Total ใน Report Footer

Total  คำนวนจาก =Sum([Input])
Total Charge คำนวนจาก =Nz(([Total]*[U Price_2 m^3]),0)    **U Price_2 m^3ในรูปตัวอย่างของGroupนี้ คือค่า98
ต้องการหา Grand Total ซึ่งค่ามาจาก Total Charge ของแต่ละกรุ๊ป รวมกันค่ะ

จากตัวอย่างที่สามารถทำได้ในแถวGrand Total Charge  คือ Sumของแต่ละInput ค่ะ นอกนั้นลองแล้วError หรือรวมค่าไม่ได้ค่ะ


16
ห้อง MS Access / Update field in table
« เมื่อ: 25 เม.ย. 61 , 09:50:07 »
ต้องการUpdate field TOTAL_ActualDay
โดยในหน้าฟอร์ม ใส่เป็นunbound textbox  ชื่อว่าActualday เพื่อนำค่าที่ได้ไปupdateลงตาราง ของแต่ละวัน

ตอนนี้Errorค่ะ
ช่วยดูโค้ดให้หน่อยค่ะ

DoCmd.RunSQL "UPDATE Monthly_FG_Imple_Sum SET [Monthly_FG_Imple_Sum].TOTAL_ActualDay ='" & Me.Actualday & "' WHERE [Monthly_FG_Imple_Sum].Date= " & Me.Date, dbFailOnError



17
ตอนนี้เพิ่มฟิลด์ Containerใน Query และนำไปแสดงข้อมูลในReport


ข้อมูลในReport



อยากจะให้ฟิลContainerใน Report สามารถInputใส่ข้อมูล เข้าในQueryนี้ได้ค่ะ
สามารถทำได้ไหมคะ

18
ห้อง MS Access / การ SUM Unbound Textbox บนForm Footer
« เมื่อ: 20 เม.ย. 61 , 12:01:02 »
สร้าง Unbound Textbox เพื่อใส่ค่า
แล้วนำไปแสดงในแถวของส่วน Detail
จากนั้นนำไปคำนวนค่าSUM ใน Form footerต่อ แต่ข้อมูล#Error

อยากทราบว่าสามารถคำนวนได้ไหมคะ
ใช้สูตร Sum([textbox])


หน้า: [1] 2