ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦bexcel¤¤¸ê®Æ·s¼W«á¡AAccess¸ê®Æªí¤¤ªº¸ê®Æ·|¦Û°Ê§ó·s

[µo°Ý] ¦bexcel¤¤¸ê®Æ·s¼W«á¡AAccess¸ê®Æªí¤¤ªº¸ê®Æ·|¦Û°Ê§ó·s

½Ð±Ð¦U¦ì°ª¤â~

¥Ø«e¸ê®Æ«¬ºA¦³¨â­Ó ¤@­Ó¬OEXCEL¥t¤@­Ó¬OAccess

·Q­nexcelªº¸ê®Æ·s¼W«á

«ö­Ó«ö¶s¡AAccess¸Ìªº¸ê®Æ´N·|¦Û°Ê§ó·s

excel:
2.png
access:
1.png
¦]¬°³o­Ó¿ý»s¥¨¶°¤]µLªk¦¨¥\

ºô¤W¬O¦³§ä¨ìª½±µ²£¥Í¤@­Ó¸ê®Æªí

¦ý¦]ÁÙ·Q­n¥Î­ì¨Óªº¸ê®Æªí¡A¤£­n¨C¦¸§ó·s´N·s¼W¤@­Ó¸ê®Æªí¡A¥u»Ý§ó·s¸ê®Æ

­n«ç»ò¦bexcel¥i¥Hª½±µ¾Þ§@accessªº¦P­Ó¸ê®Æªí©O?

³Â·Ð¤F~ÁÂÁÂ^ ^

¥»©«³Ì«á¥Ñ lpk187 ©ó 2016-9-6 13:09 ½s¿è

¦^´_ 1# Changbanana

Documents.rar (34.55 KB)
µ¹§A°Ñ¦Ò

TOP

¥»©«³Ì«á¥Ñ Changbanana ©ó 2016-9-6 15:12 ½s¿è

¦^´_ 2# lpk187


    ÁÂÁ§AªºµªÂÐ
   ¥Ø«e­Y¬O¶]¤TÄ檺¸ê®Æ©M³£¦³­Èªº¸Ü¬O³£¦³½Æ»s¹L¥h

¦ý¦³µo²{­Y¬O¤¤¶¡¦³ªÅ¸ê®Æ´NµLªk°µ¤F
¥i¥H§âkey­È§ï¦¨ID¶Ü?
ÁÙ¦³¼W¥[Äæ¦ìªº¸Ü¬O¤£¬O³o¼Ë°µ?
  1. Public Sub ¶×¥X()
  2.     Dim arr, i%
  3.     Dim myCon As Object, myRs As Object, sql$
  4.     Set myCon = CreateObject("ADODB.Connection")
  5.     Set myRs = CreateObject("ADODB.Recordset")
  6.     myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\test.accdb;"
  7.     arr = Sheets(1).Range("[color=Red]D1[/color]", Sheets(1).[A65535].End(xlUp))
  8.     Set myRs = Nothing
  9.     For i = 1 To UBound(arr)
  10.         sql = "SELECT * FROM ¸ê®Æªí1 WHERE ¸ê®Æªí1.¦WºÙ Like '" & arr(i, 1) & "';"
  11.         Set myRs = myCon.Execute(sql)
  12.         If myRs.EOF = True Then
  13.             sql = "INSERT INTO " & "¸ê®Æªí1" & "(¦WºÙ,ID,¦¨ÁZ°ê,[color=Red]¦¨ÁZ¼Æ[/color])" & _
  14.                   " VALUES('" & arr(i, 1) & "','" & arr(i, 2) & "','" & arr(i, 3) & "'[color=Red]," & arr(i, 4) & "[/color]);"
  15.             Set myRs = myCon.Execute(sql)
  16.         End If
  17.         Set myRs = Nothing
  18.     Next
  19.     Set myRs = Nothing
  20.     myCon.Close
  21.     Set myCon = Nothing

  22. End Sub
½Æ»s¥N½X
¦¨ÁZ¼Æ¬O·Q­n¼W¥[Äæ¦ìªº¸ê®Æ~

TOP

¦^´_ 3# Changbanana


   §â§AÀɮשñ¤W¨Ó§a

TOP

¦^´_ 3# Changbanana


   Àx¦s®æ¤¤¨S¦³¸ê®Æ¡A¦bVBA°}¦C¤¤¨Ã¤£·|¥H¬°¬ONull­È
¦ÓSQL»y¨¥¤¤«h¬O¥²¶·µ¹¥LNull­È
©Ò¥H¦barr¤¤¦³ªÅ¥Õ³B¡A¥²¶·§â¥¦§ï¦¨"Null"
©Ò¥H­n¦h­Ó°j°é¥h§ó§ï¥LªºªÅ­È
INSERT INTO¬O·s¼W¸ê®Æ¡A­Y­×§ïªí®æ¤¤ªº¸ê®Æ´N»Ý­n¥Î¨ìUPDATE «ü¥O
¦³ÃöSQL»yªk¡A½Ð¦Û¦æGoogle "SQL"
  1. Public Sub ¶×¥X()
  2.     Dim arr, i%
  3.     Dim myCon As Object, myRs As Object, sql$
  4.     Set myCon = CreateObject("ADODB.Connection")
  5.     Set myRs = CreateObject("ADODB.Recordset")
  6.     myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\test.accdb;"
  7.     arr = Sheets(1).Range("C1", Sheets(1).[A65535].End(xlUp))
  8.     For i = 1 To UBound(arr)
  9.         For j = 1 To UBound(arr, 2)
  10.             aa = arr(i, j)
  11.             If arr(i, j) = Empty Then
  12.                 arr(i, j) = "Null"
  13.             End If
  14.         Next
  15.     Next
  16.     Set myRs = Nothing
  17.     For i = 1 To UBound(arr)
  18.         sql = "SELECT * FROM ¸ê®Æªí1 WHERE ¸ê®Æªí1.¦WºÙ Like '" & arr(i, 1) & "';"
  19.         Set myRs = myCon.Execute(sql)
  20.         If myRs.EOF = True Then
  21.             sql = "INSERT INTO " & "¸ê®Æªí1" & "(¦WºÙ,ID,¦¨ÁZ)" & _
  22.                   " VALUES('" & arr(i, 1) & "','" & arr(i, 2) & "'," & arr(i, 3) & ");"
  23.             Set myRs = myCon.Execute(sql)
  24.         End If
  25.         Set myRs = Nothing
  26.     Next
  27.     Set myRs = Nothing
  28.     myCon.Close
  29.     Set myCon = Nothing

  30. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ lpk187 ©ó 2016-9-6 17:38 ½s¿è

¦^´_ 3# Changbanana


    ¤Ï¹L¨Ó ¦b¶×¤J¸ê®Æ®É¡Aax = myRs.GetRows¬O³£¦³¸ê®Æªº±¡ªp¤U¨Ï¨ä¦¨¬°°}¦C¡A
¦ý¬O¨ä¤¤­Y¦³ªÅ­È®É(Null)¡A¨äax°}¦C¤¤¤]·|¬°Null ©Ò¥H¤£¯à¥Î°}¦Cª½±µ¿é¤J¸ê®Æ
©Ò¥H¶×¤J¤]­n­×§ï
  1. Public Sub ¶×¤J()
  2.     Dim myRs As ADODB.Recordset '³sµ²¸ê®Æªí
  3.     Dim myCon As Object, sql$
  4.     Set myCon = CreateObject("ADODB.Connection")
  5.     Set myRs = CreateObject("ADODB.Recordset")
  6.     myCon.Open "provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & ThisWorkbook.Path & "\test.accdb;"
  7.     Sheets(1).Range("C1", Sheets(1).[A65535].End(xlUp)).Clear
  8.     sql = "SELECT * FROM ¸ê®Æªí1 ORDER BY ¸ê®Æªí1.ID;"
  9.     Set myRs = myCon.Execute(sql)
  10.     ro = 1
  11.     Do While Not myRs.EOF
  12.             Sheets(1).Cells(ro, 1) = myRs.Fields(0).Value
  13.             Sheets(1).Cells(ro, 2) = myRs.Fields(1).Value
  14.             Sheets(1).Cells(ro, 3) = myRs.Fields(2).Value
  15.             ro = ro + 1
  16.         myRs.MoveNext
  17.     Loop
  18.     Set myRs = Nothing
  19.     myCon.Close
  20.     Set myCon = Nothing
  21. End Sub
½Æ»s¥N½X

TOP

¦^´_ 4# lpk187

test.rar (34.48 KB)

¥H¤Wªþ¤WÀÉ®×~~

ÁÂÁ§AªºÀ°¦£

ÁÙ¦b¬ã¨s¤¤@@

TOP

        ÀR«ä¦Û¦b : ¡i¥Í©R¦b©I§l¶¡¡j¦òªû»¡¡G¡u¥Í©R¦b©I§l¶¡¡C¡v¤HµLªkºÞ¦í¦Û¤vªº¥Í©R¡A§óµLªk¾×¦í¦º´Á¡AÅý¦Û¤v¥Ã¦í¤H¶¡¡C¬JµM¥Í©R¥h¨Ó³o»òµL±`¡A§Ú­Ì§óÀ³¸Ó¦n¦n¦a·R±¤¥¦¡B§Q¥Î¥¦¡B¥R¹ê¥¦¡AÅý³oµL±`¡BÄ_¶Qªº¥Í©R¡A´²µo¥¦¯uµ½¬üªº¥ú½÷¡A¬M·Ó¥X¥Í©R¯u¥¿ªº»ù­È¡C
ªð¦^¦Cªí ¤W¤@¥DÃD