: ถ้าจะเอาโค้ด 1 แทรกลงในโค้ด 2 จะต้องเขียนอย่างไรครับ


0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

14 ธ.ค. 61 , 11:43:58
อ่าน 1007 ครั้ง

aek

ขอถามนะครับถ้าจะเอาโค้ด 1 แทรกลงในโค้ด 2 จะต้องเขียนอย่างไรครับ ขอบคุณครับ  :prettiness:
 
---โค้ด1----
Private Sub import_Click()
    Dim strPath As String
    Dim strFile As String
    Dim strTable As String
    Dim StrFileName As String
    Dim strextensionNew As String

    strTable = "Table1"
    strPath = "D:\textfile\"
    strFile = Dir(strPath & "*.txt")
    If strFile = "" Then
    MsgBox "ไม่พบไฟล์ที่จะ Import !!", vbCritical, "แจ้งเตือน"
    Exit Sub
    End If
    Do While strFile <> ""
    StrFileName = strPath & strFile
    DoCmd.TransferText acImportDelim, "", strTable, StrFileName, False
   
    strextensionNew = Left(StrFileName, InStrRev(StrFileName, ".") - 1) & ".xxx"
   
   
   
    Name StrFileName As strextensionNew
    strFile = Dir
    Loop
End Sub


---โค้ด2---
Option Compare Database
Option Explicit

Dim holdPercComplete As Single

Private Sub UpdateProgress(CurrentItem As Long, TotalItems As Long, taskName As String)
    Dim PercComplete As Single
    Dim intWidth As Integer
   
    Me.lblCurrentTask.Caption = taskName
   
    'Validate data
    If CurrentItem <= 0 Or TotalItems <= 0 Then
        imgProgress.Width = 0
        Exit Sub
    End If
   
    'Calculate the percentage complete
    PercComplete = CurrentItem / TotalItems
    If Int(PercComplete * 100) = Int(holdPercComplete * 100) Then
        Exit Sub
    End If
    'Save it for comparison
    holdPercComplete = PercComplete
   
    'Calculate how wide to make the progress bar
    If (PercComplete * 100) Mod 5 = 0 Then
        intWidth = (BoxProgress.Width * PercComplete)
        imgProgress.Width = intWidth
        DoEvents    'or Me.Repaint
    End If

End Sub


Private Sub Form_Load()
    Call UpdateProgress(0, 0, "Idle")
End Sub

Private Sub cmdStart_Click()
    Dim lngItem As Long
    Const lngTotal As Long = 100000
   
    Do While lngItem <= lngTotal
        lngItem = lngItem + 1
        If lngItem < 50000 Then
            Call UpdateProgress(lngItem, lngTotal, "Starting...")
        ElseIf lngItem < 75000 Then
            Call UpdateProgress(lngItem, lngTotal, "Getting there...")
        Else
            Call UpdateProgress(lngItem, lngTotal, "Almost finished...")
        End If
    Loop
   
    Call UpdateProgress(lngItem, lngTotal, "Task complete")

End Sub


 

14 ธ.ค. 61 , 23:08:22
ตอบกลับ #1

OddyWriter

ใช้คำสั่ง Call ครับ

รับจ้างทำฐานข้อมูล สอนวางระบบฐานข้อมูล Excel/ Access/ VBA Excel/ VBA Access/ SQL Server/ Database Design
แม้กระทั่งดูดวง ก็ติดต่อได้นะครับ
 
โพสต์นี้ได้รับคำขอบคุณจาก: aek


บอร์ดเรียนรู้ Access สำหรับคนไทย


 

Sitemap 1 2 3 4 5