2014-03-25 67 views
0

IHAVE的EXCELL sheeet至極由程序產生這樣 enter image description here進口EXCELL數據到MS Access表

我想導入成片的MS Access programme.how通過過濾數據來獲得這些數據輸入到相關的表格。

| DeptNo | DeptName | =>(部門表)

| StaffNo | StaffName | =>(staff table)

|部門編號|員工編號|工作日|周| =>(考勤表)

+0

您需要在Excel文件和「乾淨」它手動工作,所以它可以進入的MS Access。您可以記錄清潔過程的宏,以便更快地完成清潔過程。 – Jerry

+0

我不明白數據行StaffSummary = 803,這當然似乎沒有加起來。 – donPablo

+0

該職位並不重要。 – kbitsoft

回答

0

可以編寫一個程序概括爲 -

Revised on 3/25 late 
Dim WeAreInWorkDates As String 

For each row in worksheet 

    If ColA.value = Dept row then 
     WeAreInWorkDates = "NO" 'reset flag to false 
     get values 
     if these values don't already exist in DeptTable then 
      Insert new row into DeptTable 
     endif 

    elseIf ColA.value = Staff row then 
     WeAreInWorkDates = "NO" 'reset flag to false 
     get values 
     if these values don't already exist in StaffTable then 
      Insert new row into StaffTable 
     endif 

    elseIf ColA.value = "WorkDate" 
     bypass row 
     WeAreInWorkDates = "YES" ' set flag 

    elseIf ColA.value = "Summary" 
     bypass row 
     WeAreInWorkDates = "NO" 'reset flag to false 

    elseIf ColA.value = blanks 
     bypass row 

    elseIf WeAreInWorkDates = "YES" then   
     'get values from the row into local variables 
     Dim xxx 
     xxx = myXLS.Cells(nRow,nCol) ... etc 
     ' Prevent double posting of the XLS into the MDB tables 
     'if these values don't exist in AttendanceTable then 
     SET rst = db(Select * From AttendanceTable Where atKey = xxx(i.e. myLocalVars)) 
     if rst.BOF and rst.EOF then ' rst is empty, ergo not yet posted 
      Insert row in AttendanceTable 
     endif 

    else 
     display that we have an unknown row 
    endif 
+0

感謝這個我想要的方式。但我在vba中很差。我會試着理解。如果您可以請提供零件的實際代碼「elseIf WeAreInWorkDates 得到值 如果這些值不存在AttendanceTable然後 在考勤表中插入行」那麼我可以自己處理其他部分。 – kbitsoft

+0

我可以將工作日期和工作人員摘要之間的範圍命名爲like.range(「工作日期」,「staffsummery」)或另一個,然後它可以用於導入而不是逐個訪問。 – kbitsoft

+0

我修改了上面的內容。 WeAreInWorkDates是一個變量,用於跟蹤我們是否在WorkDates和Summary之間,因爲實際出勤行沒有行標識符。您不希望執行Range方法,而是測試每一行以事先發布到mdb並防止重複發佈。如果你剛剛在範圍內砰然響,那麼一些操作員錯誤可能會重複發佈兩次(或三次)相同的XLS ... – donPablo