- ©«¤l
- 6
- ¥DÃD
- 3
- ºëµØ
- 0
- ¿n¤À
- 10
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- 1
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2013-5-2
- ³Ì«áµn¿ý
- 2019-11-21
|
[µo°Ý] [µo°Ý] ¦³Ãö©óSQL¤£¦s¦b«hinsert¦s¦b«hupdate
½Ð°Ý¦U¦ì¤j¤j¦³Ãö©óSQL¤£¦s¦b«hinsert¦s¦b«hupdateªº°ÝÃD
§Ún±NExcelªºTable Update¨ìAccess¸ê®Æ®w¡A·í¸ê®Æ¦s¦b®É§YUpdate¤£¦s¦b®É§Yinsert
¦]¬°§Ú«D±M·~¡A¬G¤Wºô¬d¸ß¤@¯ë¤Hªº¼gªk¡A¥H¤U¤T¬q»yªk¤À§O(Select, Update, Insert)³£¯à°õ¦æ¡A¦ý§Ú¸Ó¦p¦ó¾ã¦X¡A¤~¯à¹F¨ì©O?- Private baglan As Object, rs As Object
- Sub baglanti()
- Set baglan = CreateObject("adodb.connection")
- #If VBA7 And Win64 Then
- baglan.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\SKYEYEDatabase.mdb"
- #Else
- baglan.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\SKYEYEDatabase.mdb"
- #End If
- End Sub
- Sub FP_Database_Acess()
- Sheets("Menu-FP").Visible = True
- Sheets("Menu-FP").Select
- Dim shFC As Worksheet
- 'Dim aArticle As String
- Set shFC = Sheets("Menu-FP")
- EndR = shFC.Range("A65536").End(xlUp).Row
-
- For R = 7 To EndR
- CustomerID = shFC.Cells(R, 1)
- Customer = "'" & shFC.Cells(R, 2) & "'"
- SPECID = shFC.Cells(R, 3)
- aArticle = "'" & shFC.Cells(R, 4) & "'"
- MD = "'" & shFC.Cells(R, 5) & "'"
- Qty = shFC.Cells(R, 6)
- Area = "'" & shFC.Cells(R, 7) & "'"
- Remark = "'" & shFC.Cells(R, 8) & "'"
- PNL = "'" & shFC.Cells(R, 9) & "'"
- Grade = "'" & shFC.Cells(R, 10) & "'"
- Package = "'" & shFC.Cells(R, 11) & "'"
- ICVID = shFC.Cells(R, 12)
- Path = "'" & shFC.Cells(R, 13) & "'"
- File = "'" & shFC.Cells(R, 14) & "'"
-
- Call baglanti
-
- Set rs1 = baglan.Execute("(SELECT CustomerID=" & CustomerID & ",Customer= " & Customer & ", SPECID=" & SPECID & ", MaterialDescription=" & MD & ",Qty=" & Qty & ",Area=" & Area & ",Remark=" & Remark & ", ProductNameLIMS=" & PNL & ",Grade=" & Grade & ", Package=" & Package & ",ICVID=" & ICVID & ",Path=" & Path & ",File=" & File & " FROM [FC] WHERE Article= " & aArticle & ")")
- Set rs2 = baglan.Execute("(UPDATE [FC] SET CustomerID=" & CustomerID & ",Customer= " & Customer & ", SPECID=" & SPECID & ", MaterialDescription=" & MD & ",Qty=" & Qty & ",Area=" & Area & ",Remark=" & Remark & ", ProductNameLIMS=" & PNL & ",Grade=" & Grade & ", Package=" & Package & ",ICVID=" & ICVID & ",Path=" & Path & ",File=" & File & " WHERE Article= " & aArticle & ")")
- Set rs3 = baglan.Execute("INSERT INTO [FC] (CustomerID,Customer,SPECID,Article,MaterialDescription,Qty,Area,Remark,ProductNameLIMS,Grade,Package,ICVID,Path,File) Values (" & CustomerID & "," & Customer & "," & SPECID & "," & aArticle & "," & MD & "," & Qty & "," & Area & "," & Remark & "," & PNL & "," & Grade & "," & Package & "," & ICVID & "," & Path & "," & File & ")")
-
- Set baglan = Nothing: Set rs1 = Nothing: Set rs2 = Nothing: Set rs3 = Nothing:
-
- Next
- MsgBox ("DONE")
- End Sub
½Æ»s¥N½X |
|