Dao »P SQL »yªk½d¨Ò(¤G)

¦^­º­¶


¤ÀÃþ

¼ÐÃD

¤j·N

§@ªÌ

¤é´Á

DBGrid ³]©wÄæ¦ì¼e«× ¡@ ¦Ñ©Ç 1998/8/14
DBGrid ¨ú®ø DBGrid Delete Áä¥\¯à BeforeColEdit ¨Æ¥ó ¦Ñ©Ç 1998/10/8
DBGrid ³]©w DBGrid Cell Unable BeforeColEdit ¨Æ¥ó ¦Ñ©Ç 1998/10/31
DataControl DataControl ¦p¦óÃö³¬¸ê®Æ®w Database & Recordset ¦Ñ©Ç 1998/9/29
Dao ¾Þ§@ ±N Access ¤¤ªº¬d¸ß§R°£ ¡@ ¦Ñ©Ç 1998/9/12
Dao ¾Þ§@ ¦h¨Ï¥ÎªÌÀô¹Ò¤Uªº¸ê®Æ®w¶}±Ò¼Ò¦¡ ¡@ ¦Ñ©Ç 1998/9/17
Dao ¾Þ§@ ¤å¦rÀɸê®Æ®wªº½s¿è¤Î¦^¦s ¡@ ¦Ñ©Ç 1998/8/31
Dao ¾Þ§@ ¦p¦ó¦b VB ¤¤±N Excel ¿é¥X¦¨¯Â¤å¦rÀÉ ¥Î Dao ¦ê±µ XLS & TXT ¦Ñ©Ç 1998/9/30
Dao ¾Þ§@ ±N Memo Äæ¦ì¸ê®Æ¤À¦æ ¡@ ¦Ñ©Ç 1998/10/7
Dao ¾Þ§@ MDB ¸ê®Æ®wªºÃöÁp°O¿ý§R°£°Ê§@ ¡@ ¦Ñ©Ç 1998/10/13
Dao ¾Þ§@ Åã¥Ü MDB ¸ê®Æ®wªºÀx¦s¹Ï§Î ¡@ ¦Ñ©Ç 1998/10/15
Dao ¾Þ§@ ¤@ Recordset ¦h Form ¥Î ¡@ ¦Ñ©Ç 1998/11/9
SQL »yªk µLªk°õ¦æªº¬yµ{§PÂ_ If...Then »P IIF() ¦Ñ©Ç 1998/9/14
SQL »yªk ¨Ï¥ÎÅܼƬ°¬d¸ß±ø¥ó ¡@ ¦Ñ©Ç 1998/9/14
SQL »yªk ¥H Like ¤Î ¸U¥Î¦r¤¸ªº¬d¸ß "*" & "?" ¦Ñ©Ç 1998/9/24
SQL »yªk ¬d¸ß±ø¥ó»Ý»PÄæ¦ì«¬ºA°t¦X ¦rÀY¤£¹ï¼Æ¼Lªº¿ù»~ ¦Ñ©Ç 1998/10/1
SQL »yªk ¦p¦ó¹ï¤@­ÓÄæ¦ì°µ­«Âгsµ² ¸ê®Æªíªº¥»´L¤Î¤À¨­ ¦Ñ©Ç 1998/10/3
SQL »yªk ±N¤@­ÓÄæ¦ì­È¤À¨ì¦h­Ó¸s²Õ Like & "?" ¦Ñ©Ç 1998/10/7
SQL »yªk ¦hÄæ¥æ¶°¿ï¨ú ¥Î And ¹Bºâ¦¡°µÄæ¦ì¥æ¶° ¦Ñ©Ç 1998/10/7
SQL »yªk ¥Î SQL ¶}±Ò«ü©wªº Excel Sheet ¤£­n§Ñ¤F "[" & "]" ¦Ñ©Ç 1998/10/15

Dao »P SQL »yªk½d¨Ò¨Ï¥Î»¡©ú


  1. ¥»¸ê®Æ®w½d¨Ò¥u¾A¥Î Dao ª«¥ó¡A³æ¤@¨Ï¥ÎªÌªº¾Þ§@¡A¦h¨Ï¥ÎªÌ¤Îºô¸ô¤Wªº¨Ï¥Î¡A¦]¦³§ó¦hªº­­¨î¡A¥»½d¨Ò¥¼¥²¯à¥¿½T°õ¦æ¡C¥»½d¨ÒÅwªï«DÀç§Q©Ê­Ó¤H¤Î²Õ´Âà¸ü¨Ï¥Î¡AÀç§Q¤§§Q¥Î½Ð¥ý¼x±o¥»¤H¤§¦P·N¡A¨Ó«Hµù©ú¨Ï¥Î¤è¦¡¤Î¦^ÂЦa§}¡C
  2. DBGrid¡BDBCombo ÁöÄÝ VB ¥~«Ø±±¨î¶µ¡A¦ý¦]»P Dao ¸ê®Æ®w®§®§¬ÛÃö¡A©Ò¥H¤]©ñ¥»½g°Q½×¡A¦Ó¤£¥¦ÂkÃþ¦b ActiveX ¶µ¡C
  3. ¥»½d¨Ò©Ò¦³ªºµ{¦¡½X½d¨Ò¡A¬ÒÄݤQ¤À°ò¥»ªº VB »yªk¡A¦pªG±z¬O­Ó VB User ¡AÅwªïª½±µ¤Þ¥Î©Î§ï¼g¨Ï¥Î¦b§Aªºµ{¦¡¤¤ ¡A¥»¤H¤£¥D±iµÛ§@Åv¡A¦]¬°¡A¨S¿ìªk¬d¹À¡C
  4. ¦pªG§A¬O­Ó VB ªì¾ÇªÌ¡A¤S¦³ÂI½a½a(©M¦Ñ©Ç¤@¼Ë)¡A»°§Ö§â¥»­¶¥t¦s·sÀɨì§A¦Û¤vªººÏºÐ¡AÂ÷½u«áºCºC¬Ý¡A¤]¥i¥H Copy µ¹ªB¤Í³á(¤£¥i¥H¦¬¿ú)¡C
  5. ¥»½d¨Ò³£¬O¦Ñ©Ç´X­Ó¤ë¨Ó¦b tw.bbs.comp.language °Q½×¸s²Õ¤¤¦^µªª©¤Í°ÝÃDªº¦X¿è¡A¦]¬°¬O°w¹ï°ÝÃD¸Ñ¨M¡A©Ò¦³¨Ã¨S¦³¥þ­±Æ[©Àªº¸Ñ»¡¡A¤£¾A¦X§@¬°¤Jªù¤å³¹¡A¦ý¦pªG§AŪ¤F¤Jªù®Ñ¡A©Î¬O¤W¤F¦Ñ®vªº½Ò¡A¤ß¤¤¤´¤£¬Æ©ú¥Õªº¸Ü¡A´N¥i¥H¨Ó³o§ä§ä¦³¨S¦³§A­nªºµª®×¡A¦]¬°³o³£¬O§O¤H°Ý¹Lªº°ÝÃD¡C

¦^¯Á¤Þ


³]©wÄæ¦ì¼e«×


ºÆ¨g²Ô¥K ¼¶¼g©ó¤å³¹

¸ê®Æ¶Ç¦^¦Ü DBgrid ®É,¦p¦ó©T©w¨C¤@­ÓÄæ¦ìªº¼e«×©O?¥H§KUserÁÙ­n¦Û¦æ½Õ¾ãÄæ¼eªº§xÂZ!

¦Ñ©Çµª¡G

Option Explicit
'°õ¦æ¥»µ{¦¡¡A¦b Column »P Column ¶¡«ö¨â¤U§Y¥i½Õ¾ã
'Column ¼e«×,´N¦p¦P Access ©M Excel ¾Þ§@¤è¦¡¤@¼Ë
Dim IsResize As Boolean
Dim ColNo As Integer

'³]©w DBGrid.Columns ¼e«×ªº¦Û­q¨ç¼Æ
Private Sub SetGridWidth(ByVal DG As DBGrid, ByVal ColNum As Integer)
Dim MeFont As StdFont
Dim I As Integer
Dim ColWidth As Single
Dim TempWidth As Single
    'Àx¦s Me.Form ªº­ì¦r«¬³]©w
    Set MeFont = Me.Font
    '§â Me ©M DBGrid ¦r§Î³]¬°¤@¼Ë¥H§Q­pºâ¼e«×
    Set Me.Font = DG.Font

    '¥ýºâÄæ¦ì¼ÐÃD¼e«×
    ColWidth = Me.TextWidth(DG.Columns(ColNum).Caption)
    'DBGrid.VisibleRows ªí¥Ü DBGrid Á`¦C¼Æ
    For I = 0 To DG.VisibleRows - 1
        '¥Î Me.TextWidth ºâ¸ê®Æ¦r¦ê¼e«×
        '§Q¥Î CellText ¤Î RowBookMark ¨â¤èªkªº°t¦X¡A¥i¥H¤£¥Î
        '²¾°Ê Cell «ü¼Ð¦Ó¨ú±o¯S©w Cell ¦r¦ê¡A¸Ô±¡°Ñ¾\ VB Help
        TempWidth =
Me.TextWidth(DG.Columns(ColNum).CellText(DG.RowBookmark(I)))
        '¦pªG¦r¦ê¸û¼e«h¼e«×¤¬´«
        If TempWidth > ColWidth Then
            ColWidth = TempWidth
        End If
    Next

    '¦]¬°¦Ò¼{Ãä½u¤Î¶¡¶Z¡A¥[ÂI¼e«×¤~¯à§¹¥þ®e¤U
    DG.Columns(ColNum).Width = ColWidth + ScaleX(90, vbTwips, Me.ScaleMode)

    Set Me.Font = MeFont
End Sub

Private Sub DBGrid1_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
    '³]©w½Õ¾ã¼e«×«ü¼Ð¬°¯u
    IsResize = True
    '°O¤U¨º­Ó Column ³Q½Õ¾ã
    ColNo = ColIndex
End Sub

Private Sub DBGrid1_DblClick()
    '¥u¦³·í IsResize ¬°¯u¤~½Õ¾ã¼e«×
    If IsResize Then
        '°õ¦æ SetGridWidth ¦Û­q¨ç¼Æ
        'ColNo ¬°Âù¦V½bÀY«eªº Column ½s¸¹
        SetGridWidth DBGrid1, ColNo
    End If
End Sub

Private Sub DBGrid1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
    'ÁÙ­ì¼e«×«ü¼Ð¬°¥¼½Õ¾ã
    IsResize = False
End Sub

¦^¯Á¤Þ


±N Access ¤¤ªº¬d¸ß§R°£


¹L¤F¼öÅʪº©u¸`... ¼¶¼g©ó¤å³¹

½Ð°Ývb¦p¦ó±Naccess¤¤ªº¬d¸ß§R°£....¤p§Ì¥ÎCreateQueryDef¦baccess¤¤«Ø¥ß¤F¤@­Ó¬d¸ßStuQry2  DB.CreateQueryDef("StuQry2", QSQL) ½Ð°Ý­n¤U¦p¦ó«ü¥O¤~¯à±N³o­Óview§R°£¡H

¦Ñ©Çµª¡G

DB.QueryDefs.Delete "StuQry2"

¦^¯Á¤Þ


µLªk°õ¦æªº¬yµ{§PÂ_


¹L¤F¼öÅʪº©u¸`... ¼¶¼g©ó¤å³¹

¦U¦ì°ª¤â.¤p§Ì¥ÎVB·Q±NACCESS¤¤ªº¾Ç¥Í¸ê®Æ®wªº¦~¯Å©¹¤W¥[¤@¦~.½Ð°Ý§Úªº¼gªk­þ¸Ì¿ù¤F.ÁÂÁ¡G
       SQL="UPDATE STUM1 SET YEAR=CASE WHEN YEAR='°ê¤@'THEN'°ê¤G'"
       SQL=SQL & "WHEN YEAR'°ê¤G'THEN'°ê¤T'"
       SQL=SQL&"END"

¦Ñ©Çµª¡G

  1. ¦b SQL ¤¤¤£¯à¨Ï¥Î IF,Case µ¥¦h¦æ¬yµ{±±¨î±Ô­z¡A¦pªG§Aªº¸ê®Æ®w¬O MDB¡A«h¥i¥Î IIF() ¨ç¼Æ´À¥N¡C
    SQL="UPDATE Stum1 SET Stum1.Year = "
    SQL=SQL & "IIf([stum1]![Year]='°ê¤@','°ê¤G','°ê¤T') "
    SQL=SQL & "WHERE ((([Stum1]![Year])<>'°ê¤T'));"
  2. IIf() ¨ç¼Æ¦b Jet SQL ÁöµM¤ä´©¡A¦ý ANSI SQL «h¥¼¥²¤ä´©¡A©Ò¥H§AÁÙ¬O¤À¨â­ÓSQL °õ¦æ¸û¦n¡G

¦^¯Á¤Þ


¦h¨Ï¥ÎªÌÀô¹Ò¤Uªº¸ê®Æ®w¶}±Ò¼Ò¦¡


µL¤ß ¼¶¼g©ó¤å³¹

¤@­ÓAccessÀÉ®×  ,  ¦p¦ó³Q¨â­ÓAP¶}±Ò,§Ú¥ý¥ÎAccess¶}±Ò, µM«á¶]VBµ{¦¡¶}±Ò³£·|³y¦¨¿ù»~¡H

¦Ñ©Çµª¡G

¸Õ¸Õ¬Ý¤U­±ªº¤è¦¡¦æ¤£¦æ

Option Explicit
Dim Db As Database
Dim Rs As Recordset

Private Sub Form_Load()
    Set Db = OpenDatabase("YourDataName")
    Set Rs = Db.OpenRecordset("YourTableName", dbOpenDynaset, dbSeeChanges,
dbPessimistic)

    Set Data1.Recordset = Rs
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Rs.Close
    Db.Close
End Sub

¦b¸ê®Æ®w¦h¨Ï¥ÎªÌÀô¹Ò¤U¡AOpenRecordset ¤èªkªº type, options, lockedits °Ñ¼Æ¦p¦ó¤U¡A·|Åܪº«Ü½ÆÂø¡A½Ð¦Û¦æ°Ñ¦Ò Dao Help ¡AOpenDatabase and OpenRecordset¡C

¦^¯Á¤Þ


¨Ï¥ÎÅܼƬ°¬d¸ß±ø¥ó


«Ê¾÷Åo ¼¶¼g©ó¤å³¹ ...

½Ð°Ývbµ{¦¡°õ¦æ®É¥L»¡°Ñ¼Æ¤£¨¬,¹w´Á¬Oc..¬O¨º¸Ì¥X¤F°ÝÃD,µ{¦¡¦p¤U¡G

Private Sub CmdFind_Click()
Dim cinput As String
Dim QDpic As Database
Dim QDpicer As Recordset
cinput = InputBox("½Ð¿é¤J±ý¬d¸ß¤§¸ê®Æ", "¸ê®Æ®w¬d¸ß")
Set QDpic = OpenDatabase("c:\vb4\1\class.mdb")
Set QDpicer = QDpic.OpenRecordset("select * from class where [©m¦W]=NameText")

¦Ñ©Çµª¡G

Set QDpicer = QDpic.OpenRecordset("select * from class where [©m¦W]= '" & cinput & "'")

¦^¯Á¤Þ


¥H Like ¤Î ¸U¥Î¦r¤¸ªº¬d¸ß


±H¥óªÌ: f9853315

¤p§Ì¥Ø«e©Ò¼g¤§µ{¦¡¤D¬O¥H¤@textbox§@¬°ÃöÁä¦r¤§¿é¤J,±µµÛ¥Hsql»yªk¤¤select where»yªk¶i¦æ¸ê®Æ®w¬d¸ß,¥Ø«e¶È¯à¦btextbox¤¤¿é¤J³æ¤@¦r¦ê¨Ó¬d¸ß.¦]¦¹²{¦bªº§xÂZ¬O¦p¦ó¯à¦btextbox¤¤¿é¤J¦h­Ó¦r¦ê,µM«á¥H¥¬ªL¹Bºâ¦¡(and,or....)¨Ó¬d¸ß,sql»yªk­n«ç»ò¼g?

¦Ñ©Çµª¡G

  1. ¦r¦êµLªk°µ And & Or ¹Bºâ¡C
  2. §A¥i¥H§ï¥Î Like °t¦X¸U¥Î¦r¤¸¡A½d¨Ò¦p¤U¡C
    Text1.Text="VB"
    Text2.Text="¦Ñ©Ç"
    Text3.Text="¨Ò"

    SELECT * FROM YourTable WHERE SomeField LIKE "*" & Text1.Text & "*" & Text2.Text & "*" & Text3.Text & "*"

dreamlim ºô¤Í¨Ó¨ç«ü¥¿¡G

§A¦b "¥H Like ¤Î ¸U¥Î¦r¤¸ªº¬d¸ß"¤å³¹¤¤©Ò¨Ï¥ÎªºSQL ¸U¥Î¦r¤¸¬° "*",¦ý³o¬OVB Jet Engine ¨Ï¥Îªºªº¦r¤¸,¦b¼Ð·ÇªºSQL ©w¸q¤¤,¨ÃµL * ªº©w¸q,À³§ï¬°¡G

JET SQL Standard SQL Note
* % ¡@
# _ ¬°under line

¦Ñ©Çµª¡G

·PÁ dreamlim ¨Ó¨ç«ü¥¿¡AJet SQL ©M Standard SQL Áö¤j¦P¦Ó¤p²§¡A¦ý¨s³ºÁÙ¬O¦³©Ò®t²§ªº¡A¦b¦¹¦A¦¸´£¿ô¤j®a¡A¥»½g©Ò¦³½d¨Ò¡A³£¬O³æ¾÷ MDB ¸ê®Æ®wªº¾Þ§@½d¨Ò¡A¦pªG§AÂà¥Î¨ì§Oªº¸ê®Æ®w¡A¹ï©ó SQL ªº¨Ï¥Î®t²§¡A¤@©w­n¯S§Oª`·N¡C

¦^¯Á¤Þ


¤å¦rÀɸê®Æ®wªº½s¿è¤Î¦^¦s


¨«¹L¥|¤è¦^¨ì­ìÂI ¼¶¼g©ó¤å³¹

§Ú»Ý­n±N¤@¨Ç¤å¦rÀÉ¡]*.txt¡^¦bµ{¦¡°õ¦æ®É¤~Âà´«¦¨mdb¸ê®Æ®wÀɤ¤ªº´X±i¸ê®Æªí³æ¡A§Ú·|¦bµ{¦¡¤¤ ¹ï¨ä­×§ï¡A¥B§Æ±æ­×§ï§¹«á¤£¥u¯à¦^¦s¦Ü¸ê®Æªí³æ¤¤¡AÁ٧Ʊæ¯à¦s¦¨­û¨Óªº¤å¦rÀɧΦ¡¡A¤£ª¾¹D³o­n«ç»ò°µ°Ú¡H¡H

¦Ñ©Çµª¡G

À³¾Þ§@ VB ªº Dao ª«¥ó°µ¥H¤U°Ê§@¡G

  1. ²£¥Í MDB ÀɮסA¦p¡G
    Set Ws = DBEngine.Workspaces(0)
    Set DB = Ws.CreateDatabase(App.Path & "\textlink.mdb", dbLangGeneral)
  2. ²£¥Í¤å¦rÀɳsµ²ªí
    Set Td = DB.CreateTableDef("DataLink")
    Td.Connect = "TEXT;DATABASE=" & App.Path
    Td.SourceTableName = "datatest.txt"
    DB.TableDefs.Append Td
  3. ²£¥Í[¸ê®Æªí²£¥Í¬d¸ß]
    Set Qd = DB.CreateQueryDef("CreatQry")
    Qd.SQL = "SELECT * INTO DataEdit FROM DataLink;"
    Qd.Execute
  4. ¥Î²£¥Í¸ê®Æªí¬d¸ß²£¥Í¥i¨Ñ½s¿è­×§ïªº Table
    Set DB = OpenDatabase(App.Path & "\textlink.mdb")
    '§R°£Âªº½s¿èªí DataEdit
    DB.TableDefs.Delete "DataEdit"
    'CreatQry ¬O¨Ì¤å¦rÀɤº®e²£¥Í¸ê®Æªí¤§«Ø¥ß¬d¸ß
    Set Qd = DB.QueryDefs!CreatQry
    '°õ¦æ­««Ø DataEdit Table ¤§¥\¯à
    Qd.Execute
    Qd.Close
  5. ¶}±Ò Table ½s¿è­×§ï
    Set Rs = DB.OpenRecordset("DataEdit", dbOpenDynaset)
  6. ±N½s¿è¹L«áªº Table ¡A¥Î VB File I/O ªº³¯­z¡A¨Ì®æ¦¡¤@µ§¤@µ§­«·s¦^¼g­ì¤å¦rÀÉ¡C
    »Ý¥Îµ{¦¡±Ô­z»á¦h¡A½Ð°Ñ¦Ò¤U­±ªº§¹¾ã½d¨Ò¤¤ªº btnUpdate_Click() µ{§Ç¡C
  7. ¥H¤U¬O¦U¨BÆJ°õ¦æ¤èªk¤§§¹¾ã½d¨Ò¡G
    VERSION 5.00
    Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
    Begin VB.Form frmTextLink
    Caption = "²©ö¤å¦rÀɸê®Æ®w½s¿è¾¹"
    ClientHeight = 4200
    ClientLeft = 60
    ClientTop = 345
    ClientWidth = 6120
    LinkTopic = "Form1"
    ScaleHeight = 4200
    ScaleWidth = 6120
    StartUpPosition = 3 '¨t²Î¹w³]­È
    Begin VB.CommandButton btnUpdate
    Caption = "§ó·s¤å¦rÀÉ"
    BeginProperty Font
    Name = "·s²Ó©úÅé"
    Size = 9
    Charset = 136
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 495
    Left = 4800
    TabIndex = 2
    Top = 3480
    Width = 1215
    End
    Begin VB.CommandButton btnQuit
    Caption = "µ²§ô"
    BeginProperty Font
    Name = "·s²Ó©úÅé"
    Size = 9.75
    Charset = 136
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 495
    Left = 4800
    TabIndex = 1
    Top = 240
    Width = 1215
    End
    Begin MSDBGrid.DBGrid DBGrid1
    Bindings = "textlink.frx":0000
    Height = 3375
    Left = 240
    OleObjectBlob = "textlink.frx":0010
    TabIndex = 0
    Top = 120
    Width = 4335
    End
    Begin VB.Data Data1
    Caption = "Data1"
    Connect = "Access"
    DatabaseName = ""
    DefaultCursorType= 0 '¹w³]ªº¸ê®Æ«ü¼Ð
    DefaultType = 2 '¨Ï¥Î ODBCDirect
    Exclusive = 0 'False
    Height = 405
    Left = 240
    Options = 0
    ReadOnly = 0 'False
    RecordsetType = 1 '°ÊºA¶°(Dynaset)
    RecordSource = ""
    Top = 3600
    Width = 4380
    End
    End
    Attribute VB_Name = "frmTextLink"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option Explicit

    '¥»µ{¦¡¥²³Æ¤§°t¦XÀÉ®× DataTest.txt
    Dim Ws As Workspace
    Dim DB As Database
    Dim Td As TableDef
    Dim Qd As QueryDef
    Dim Rs As Recordset
    '¸ê®ÆÀɬO§_³Q§ó§ï¤§µù¼Ð
    Dim DataIsChange As Boolean

    Private Sub btnQuit_Click()
    Unload Me
    End Sub

    Private Sub btnUpdate_Click()
    Dim FileHandle As Integer
    Dim I As Long, J As Long
    Dim OutString As String

    Me.MousePointer = 11

    FileHandle = FreeFile
    Open App.Path & "\datatest.txt" For Output As #FileHandle

    '¿é¥X¤å¦rÀɪºÄæ¦ì¦WºÙ
    OutString = Chr(34)
    'Chr(34)=["]
    For I = 0 To Rs.Fields.Count - 1
    OutString = OutString & Rs.Fields(I).Name & Chr(34) & "," & Chr(34)
    Next
    '¥h±¼¦r§À³Ì«á¤@­Ó³r¸¹ "," ¤Î Chr(34)
    OutString = Mid(OutString, 1, Len(OutString) - 2)
    Print #FileHandle, OutString

    '¿é¥X¤å¦rÀɪºÄæ¦ì¤º®e
    Rs.MoveFirst
    Do While Not Rs.EOF
    OutString = Chr(34)
    For I = 0 To Rs.Fields.Count - 1
    OutString = OutString & Rs.Fields(I).Value & Chr(34) & "," & Chr(34)
    Next
    OutString = Mid(OutString, 1, Len(OutString) - 2)
    Print #FileHandle, OutString
    Rs.MoveNext
    Loop

    'Ãö³¬¤å¦rÀÉ
    Close #FileHandle
    '¦]¬°¸ê®Æ¤w¦^¦s¤å¦rÀÉ¡A©Ò¥H DataIsChange=False
    DataIsChange = False

    Me.MousePointer = 0
    End Sub

    Private Sub DBGrid1_AfterUpdate()
    '¸ê®Æªí¦³§ó°Ê«h±N§ó°Êµù¼Ð³]¬° True
    DataIsChange = True
    End Sub

    Private Sub Form_Load()
    Dim DbOpen As Boolean

    '¦pªG¸ê®Æ®w¥¼²£¥Í«h²£¥Í¸ê®Æ®w
    If Dir(App.Path & "\textlink.mdb") = "" Then
    CreatMdbFile
    DbOpen = True
    End If

    '¤w¦³¸ê®Æ®w«h°õ¦æ¸ê®Æªí­««Ø
    If Not DbOpen Then
    ReBuildTable
    End If

    '¶}±Ò¸ê®Æ¿ý
    Set Rs = DB.OpenRecordset("DataEdit", dbOpenDynaset)

    'DataControl ¨ì³Ì«á¤@µ§ªí·s¼W¸ê®Æ
    Data1.EOFAction = 2
    'DBGrid ¤¹³\·s¼W¡B§R°£¸ê®Æ
    DBGrid1.AllowAddNew = True
    DBGrid1.AllowDelete = True

    Set Data1.Recordset = Rs
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    Dim Answer

    '¦pªG¸ê®Æ¦³§ó°Ê¦Ó©|¥¼¦^¦s
    If DataIsChange Then
    '°õ¦æ²×¤î½T»{
    Answer = MsgBox("§A¸ê®Æ¥¼¦sÀÉ¡A½T©w­nÂ÷¶}¶Ü¡H", vbYesNo, _
    "²×¤î½T»{")
    'µª§_«h¤£²æÂ÷
    If Answer = vbNo Then
    Cancel = True
    Exit Sub
    End If
    End If

    On Error Resume Next
    Rs.Close
    DB.Close
    Ws.Close
    End Sub

    '²£¥Í textlink.mdb ¸ê®Æ®w¤§°Æµ{§Ç
    Private Sub CreatMdbFile()
    '²£¥Í¸ê®Æ®w
    Set Ws = DBEngine.Workspaces(0)
    Set DB = Ws.CreateDatabase(App.Path & "\textlink.mdb", dbLangGeneral)

    '²£¥Í¤å¦rÀɳsµ²ªí
    Set Td = DB.CreateTableDef("DataLink")
    Td.Connect = "TEXT;DATABASE=" & App.Path
    Td.SourceTableName = "datatest.txt"
    DB.TableDefs.Append Td

    '²£¥Í¥i¨Ñ½s¿è¤§ DataEdit Table
    Set Qd = DB.CreateQueryDef("CreatQry")
    Qd.SQL = "SELECT * INTO DataEdit FROM DataLink;"
    Qd.Execute

    Qd.Close
    End Sub

    '­«¸m¥i½s¿è¸ê®Æªí¤§°Æµ{§Ç
    Private Sub ReBuildTable()
    Set DB = OpenDatabase(App.Path & "\textlink.mdb")
    '§R°£Âªº½s¿èªí DataEdit
    DB.TableDefs.Delete "DataEdit"
    'CreatQry ¬O¨Ì¤å¦rÀɤº®e²£¥Í¸ê®Æªí¤§«Ø¥ß¬d¸ß
    Set Qd = DB.QueryDefs!CreatQry
    '°õ¦æ­««Ø DataEdit Table ¤§¥\¯à
    Qd.Execute
    Qd.Close
    End Sub
  8. ¨Ï¥Î¤å¦rÀɤ§®æ¦¡¡G
    "No","Name","Level","Class"
    "0001","¾G¹Å¹Å","1","¥Ò"
    "0002","¿à¬K·½","2","¤þ"
    "0003","³¢¬K¾ð","2","¥Ò"
    "0004","ªL¦w­}","2","¥Ò"
    "0005","³¯«iªQ","2","¤A"
    "0006","¦óªá­»","1","¤A"
    "0007","»¯¦¨¥\","3","¤þ"
    "0008","¼B¨q¬ü","2","¥Ò"
    "0009","¼B®Ûªá","3","¤A"

¦^¯Á¤Þ


DataControl ¦p¦óÃö³¬¸ê®Æ®w


®öº©»P·Å¬Xªº¤½ÃÉ ¼¶¼g©ó¤å³¹

¬°¤FÀ£ÁY MDB ¸ê®Æ®w¡A¥²¶·¥ý§â³QÀ£ÁYªº¸ê®Æ®wÃö³¬¡A¦ý¦p DBgrid ©M DataControl ¤´©M¸ê®Æ®wÁpµ²¡A¨º­n¦p¦ó¥ýÃö±¼¸ê®Æ®w¡AÀ£ÁY§¹¦A³sµ²¤W©O¡H

¦Ñ©Çµª¡G

  1. ¥Îª«¥óÅܼƶ}±Ò¸ê®Æ®w
  2. Ãö³¬ DataControl ³sµ²¸ê®Æ®w
  3. DataControl ­«·s³sµ²¸ê®Æ®w

¦^¯Á¤Þ


¦p¦ó¦b VB ¤¤±N Excel ¿é¥X¦¨¯Â¤å¦rÀÉ


º©«L~ ¼¶¼g©ó¤å³¹

½Ð°Ý~~Excel°µ¦¨ªºÀÉ®×~~¦p¦ó¥ÎvbÂন.txtÀÉ~~

¦Ñ©Çµª¡G

  1. °µªk¤£¥u¤@ºØ¡A¦ý¦Ò¼{¬Ù¨Æ¤Î¤£¶·¾a Excel ª«¥ó¡A¥H±Ä¥Î Dao ¦ê±µ¤è¦¡³Ì¬°«K§Q¡C
  2. ¥Î MDB ¶} Excel ¡A¤èªk½Ð°Ñ¦Ò [Dao »P SQL »yªk½d¨Ò(¤@)] ¤¤¦b Dao ¤¤¶}±Ò Excel Àɮתº½d¨Ò¡C
  3. ¦A±N table ¸ê®Æ¿é¥X¦¨¤å¦rÀÉ¡A¤èªk½Ð°Ñ¦Ò¥»½d¨Ò [¤å¦rÀɸê®Æ®wªº½s¿è¤Î¦^¦s] ¡C

¦^¯Á¤Þ


¦p¦ó¹ï¤@­ÓÄæ¦ì°µ­«Âгsµ²


±H¥óªÌ: ¿c©ú¼w

  1. ¦b SQL ¸óªí¬d¸ß¤¤¡A¦p¦ó°µ¨ì¥D¯Á¤Þªíªº¦h­ÓÄæ¦ìÃöÁp¨ì³Q¯Á¤Þªíªº¦P¤@­ÓÄæ¦ì¡H
  2. §Úªº¸ê®Æªíµ²ºc¦p¤U¡G
  3. TableB ªº B1 ©M B2 ¹ï¬M¨ì TabelA.A_ID ªº ¡A§Ú§Æ±æ TabelB ¨Ì¨ä B1¡AB2 Ä檺¤º®e¦ÓÅã¥Ü¬Û¹ï¬Mªº A1 Äæ¦ì­È¡Aµ²ªG§Æ±æ¹³¤U¦C¤@¼Ë¡G
  4. §Ú¥Î SQL JOIN ±Ô­z¡A¥u¯à¦b Q1 ©Î Q2 ¤¤¿ï¾Ü¨ä¤@¡A¥i§_¨â¼Ë³£¯àÅã¥Ü¬Û¹ï¬M TabelA.A1 ­È©O¡H

¦Ñ©Çµª¡G

  1. ³oµLªk¥Î³æ¤@ªº SQL ¬d¸ßµª¦¨¡A¦Ó¬O¥Î QueryDef ¬° TableA °µ¥X¤@­Ó¤À¨­¡A³s¦P TableA ³o­Ó¥»´L¡A´N¦³¬Û¦P°O¿ýªº¨â­Ó¸ê®Æªí¨Ó©M TableB Ápµ²¹ï¬M¡C
  2. ¥H¤U¬°»¡©ú¤°»ò¬O Table ¥»´L¡H¤°»ò¬O QueryDef ¤À¨­¡H§Ú­Ì°®¯Ü¥Î¨â­Ó TableA ªº QueryDef ¤À¨­¨Ó¸ò TabelB ÃöÁp¡C
  3. »s§@ Table ¤À¨­ A_Join_B1 ¤Î A_Join_B2¡G
  4. ¥Î¸óªí¬d¸ß¬° B1 ©M B2 ¤À§OÁp¤W TabelA¡G
  5. ´N³o¼Ë¡A§Q¥Î QueryDef ¥i¥H¬° Tabel ©µ¦ù¥XµL­­¦hªº¤À¨­¡A¤]´N¬O»¡¤@­Ó¸ê®Æªí¥i¥H¦³³\¦h­ÓÄæ¦ìÃöÁp¤@­ÓÄæ¡A¨Ã¥B©¼¦¹¥i¥H¦³¤£¦Pªº³]©w­È¡C

¦^¯Á¤Þ


±N¤@­ÓÄæ¦ì­È¤À¨ì¦h­Ó¸s²Õ


¯_¯_ ¼¶¼g©ó¤å³¹

§Ú­Ì¦³¤@­ÓÃÄ«~ªºtable·íªì³]­p½s¸¹ªº®É­Ô¤w¸g¦b½s½X¤W³]­p¦n¡A¨Ò¦p 010203¡G

  1. «e¨â½X...¥Nªí¤HÅé¨t²Î¤ÀÃþ
  2. ¤¤¶¡¨â½X   ¥NªíÃĪ«ªº¤ÀÃþ
  3. «á¨â½X   ¥Nªí¨C­ÓÃÄ«~ªº½s¸¹

²{¦b·Q­n»s§@¤@±i³øªí¥²¶·­n¤ÀÃþ¡ASQL¦³¿ìªkª½±µ§P§O§Úªº½s½X¶Ü?´N¬O¥i¥H§â010203³o­ÓÃÄ«~...ª½±µ¦w±Æ¨ì01³o­Ó¨t²Î¤ÀÃþ¤Uªº02ªº³o­ÓÃÄ«~¤ÀÃþ¶Ü?ÁÙ¬O§Ú±o§â¤@­ÓÄæ¦ì¤À¦¨¤T­ÓÅܦ¨ 01 02 03 ©O?

¦Ñ©Çµª

¤£¶·­n¤À¤T­ÓÄæ¦ì¡A¥i¥H¥Î Like °t¦X¸U¥Î¦r¤¸°µ¡G

¦ý¦³¤@­Ó«Ü­«­nªº¥ý¨M±ø¥ó¡A¨C¤@Ãþ¦û¥Îªº½X¼Æ»Ý©T©w¡A¤£¥i¦b¤£¦P°O¿ý¤¤¦³¤£¦Pªº±`µu¡C

¦^¯Á¤Þ


¦hÄæ¥æ¶°¿ï¨ú


±H¥óªÌ: ¼B½å²» ¥D¦®: ¸ê®Æ®w¨D¨ä¥æ¶°

  1. ¦³¤@¸ê®Æ®w,¦pªG¥H²Å¦X"±ø¥ó¤@"ªº±ø¥ó¤U¥h·j´M,±o¨ìªº    µ²ªG¬°"¶°¦X¤@";
  2. ¥H²Å¦X"±ø¥ó¤G"ªº±ø¥ó¤U¥h·j´M,±o¨ìªºµ²ªG¬°"¶°¦X¤G";
  3. ¥H²Å¦X"±ø¥ó¤T"ªº±ø¥ó¤U¥h·j´M,±o¨ìªºµ²ªG¬°"¶°¦X¤T";
  4. ½Ð°Ý¦p¦ó¥Ñ"¶°¦X¤@"¡B"¶°¦X¤G"    ¤Î"¶°¦X¤T"¨ú±o¨ä¥æ¶°,¥i§_¨Ï¥ÎSQL»y¨¥?

¦Ñ©Çµª¡G

SQLString="SELECT * FROM DataTable WHERE Field1=±ø¥ó¤@ AND Field2=±ø¥ó¤G AND Field3=±ø¥ó¤T;"

¦^¯Á¤Þ


±N Memo Äæ¦ì¸ê®Æ¤À¦æ


°@¸Û¨Ñ¾i´I¶QÂùÁ{ ¼¶¼g©ó¤å³¹

¥Ñ©ó§Ú¦b¦C¦L³øªí¤¤»Ý­n¸Ô²Óªº¦æ¼Æ¸ê®Æ¡A§_«h³]­p¦nªº®æ¦¡´N·|¶Ã±¼¡A¦ý¬O§Ú¦bVB¤¤§ä¤£¨ì­pºâ³ÆµùÄæ¦æ¼Æªº¤èªk¡A³oÂI¯uªº«Ü§xÂZ¡C

¦Ñ©Çµª¡G

  1. Dao ª«¥ó¤¤¨ÃµL¤À¦æªºÄÝ©Ê©M¤èªk¥i¨Ñ¾Þ§@¡A§Ú­Ì¥²¶·¥t¼gµ{¦¡¡C
  2. µ{¦¡ªº«ä¦Ò¤è¦V¬O§â Memo ¤º®e·í°µ¤@­Óªø¦r¦ê¡A§Ú­Ì¥Î Field.GetChunck ¤èªk§â¥¦§ì¨ì¦r¦êÅܼƤ¤«á¡A´Nª½±µ¥Î VB ¦r¦ê³B²z¨ç¼Æ¨Ó§â¥¦¤Á¦¨¤@¤p¬q¤@¤p¬q©T©wªø«×ªº¦r¦ê¡C
  3. ½d¨Ò¦p¤U¡G
    Option Explicit

    '´ú¸Õ¥»µ{¦¡½Ð¦bªí³æ¤W©ñ Command1,List1
    Dim Db As Database
    Dim Rs As Recordset
    'ArrayString() ¬O¤À¦C¦r¦ê
    Dim ArrayString() As String

    Private Sub Command1_Click()
    '§ì Memo ¦r¦êÅܼÆ
    Dim LongString As String
    '§PÂ_¦r¦ê
    Dim ShortWord As String * 1
    '¤À¦C¦r¦ê
    Dim LongWord As String
    Dim I As Long, J As Integer, K As Byte
        Rs.MoveFirst
        '°²³]Äæ¦ì NOTE ¬O Memo Äæ¦ì
        LongString = Rs!NOTE.GetChunk(0, Rs!NOTE.FieldSize)

        For I = 1 To Len(LongString)
            ShortWord = Mid(LongString, I, 1)
            Select Case ShortWord
                '¸I¨ì¤À¦æ¦r¤¸´N¥t°_¤@¦C
                Case Chr(13)
                    ReDim Preserve ArrayString(J)
                    ArrayString(J) = LongWord
                    J = J + 1
                    K = 0
                    LongWord = ""
                '¸I¨ìÂk¦ì¦r¤¸´N¸õ¹L
                Case Chr(10)

                Case Else
                    '¤¤¤å¦r³B²z
                    If Asc(ShortWord) < 0 Then
                        '¤@¦C°²³] 20 Byte ªø«×
                        If K < 19 Then
                            '¤@­Ó¤¤¤å¨â Byte
                            K = K + 2
                            LongWord = LongWord + ShortWord
                        'º¡ 20 Byte ¥t°_¤@¦C
                        Else
                            ReDim Preserve ArrayString(J)
                            ArrayString(J) = LongWord
                            J = J + 1
                            K = 0
                            LongWord = ShortWord
                       End If
                    Else
                        If K < 20 Then
                            '¤@­Ó­^¤å¤@ Byte
                            K = K + 1
                            LongWord = LongWord + ShortWord
                        Else
                            ReDim Preserve ArrayString(J)
                            ArrayString(J) = LongWord
                            J = J + 1
                            K = 0
                            LongWord = ShortWord
                       End If
                    End If
            End Select
        Next

        '¦pªGÁÙ¦³¦r¦ê¯d¦b LonWord ùØ«h¦A¼W¤@¦C
        If Len(LongWord) > 0 Then
            ReDim Preserve ArrayString(J)
            ArrayString(J) = LongWord
        End If

        '§âµ²ªG©ñ¨ì ListBox ùØÅã¥Ü
        For I = 0 To UBound(ArrayString)
            List1.AddItem ArrayString(I)
        Next
    End Sub

    Private Sub Form_Load()
        Set Db = OpenDatabase("c:\test\mytest.mdb")
        Set Rs = Db.OpenRecordset("student")
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
        Rs.Close
        Db.Close
    End Sub

¦^¯Á¤Þ


¨ú®ø DBGrid Delete Áä¥\¯à


Eric ¼¶¼g©ó¤å³¹

¦p¦ó¨ú®ø DBGrid ªº Delete Áä¥\¯à¡A¥H§K¨Ï¥ÎªÌ»~§R¸ê®Æ¡H

¦Ñ©Çµª¡G

Private Sub DBGrid1_BeforeColEdit(ByVal ColIndex As Integer, ByVal KeyAscii
As Integer, Cancel As Integer)
    If KeyAscii = vbKeyDelete Then
        Cancel = True
    End If
End Sub

¦^¯Á¤Þ


MDB ¸ê®Æ®wªºÃöÁp°O¿ý§R°£°Ê§@


popo ¼¶¼g©ó¤å³¹

½Ð°Ý¦bvb¤¤¦p¦ó¦P®É§R°£¤@­Ó¥H¤W¸ê®Æ®w¤¤ªº¸ê®Æ¡C¦U¸ê®Æ®w¤¤¦³¥DÁä­È¬ÛÃöÁp,§R°£µ{¦¡À³¸Ó«ç»ò¼g¡H

¦Ñ©Çµª¡G

  1. .´N¦P¤@ MDB ªº¨â­Ó Table ¨Ó»¡¡G
  2. ´N¨â­Ó MDB ªº¨â­Ó Table ¨Ó»¡¡G

¦^¯Á¤Þ


Åã¥Ü MDB ¸ê®Æ®wªºÀx¦s¹Ï§Î


Pony ¼¶¼g©ó¤å³¹

½Ð°Ý¦p¦ó¨Ï¥ÎDAO¨Ó´¡¤J¤@­Ó¹ÏÀɨì¸êͨ®w¤¤¡C¡C¡C¡C°£¤F¨Ï¥ÎDATA CONTROL¤§¥~¡C¡C¡C¡C

¦Ñ©Çµª¡G

¹ï©ó MDB ¹ÏÀÉ¡A¸g§Ú­Ì³\¦hºô¤Í´ú¸Õµ²ªG¦p¤U¡A§Æ±æ¤j®a°Ñ¦Ò¤@¤U¡A¦]¬°«ç»ò§â¹ÏÀÉ©ñÄæ¦ìùØ¡AÃö«Y¤é«á¨Ï¥Î«Ü¤j¡G

  1. °ò¥»¤W¥Î Access ©M¥Î VB ±N¹ÏÀÉ´¡¤JÄæ¦ì¤º¡A©¼¦¹µLªk¬Û¬y¥Î¡C
  2. ¦b Access ´¡¤Jªº¬O§t¦³«Ø¥ß¹ÏÀÉÀ³¥Îµ{¦¡ªºÀÉÀY¸ê®Æ¡A¬O¬° OLE «¬ºA¸ê®Æ¡C
  3. VB ´¡¤Jªº¬O¤G¶i¦ì¸ê®Æ(¤£¥u¹ÏÀÉ¡A©Ò¦³¤G¶i¦ìÀɬҥi¥H¦¹¤è¦¡´¡¤J¡C)
  4. ¥Î Access ´¡¤Jªº¹ÏÀÉ¡A¯à¥Î VB ªº OLE Control »P DataControl ³z¹L DataCombine ¤è¦¡ÂsÄý(·s¼W­×§ïÁÙ¬O¦³°ÝÃD¡A¦pªG¦³ºô¤Íª¾¹D«ç»ò·s¼W­×§ï¡A½Ð§i¶D¤j®a¡C)
  5. ¥Î VB ´¡¤J¹ÏÀɦ³¤U¦C¨â¤è¦¡¡G
  6. AppendChunck ¤èªk¾A¥Î©ó¦bºÏºÐùؤw¦³ªº¹ÏÀÉ¡C
  7. ¦pªG¬Oµ{¦¡ùتºÃ¸¹Ï¡A¤£³z¹LºÏºÐ¡A¨º¥²¶·¥Î PictureBox ©M DataControl ¬Û³sµ²¤èªk
  8. ¤£ºÞ¬O¨ººØ¤èªk¡A³£µLªk¦b Access ªº Form ªí³æùسQÂsÄý¡C
  9. ©Ò¥H VB ªºÂk VB ¡AAccess ªºÂk Access ¡A§A¥²¶·¦b¹Ï§Î¸ê®Æ®w³W¹º¤§ªì¡A´N¨M©w¦n¬O­n¦b VB ùإΩάO¦b Access ùإΡA°µ¨ì¤@¥b¤~§ïÅÜ¥D·N¡A©Ò¦³¦s¹Ï°Ê§@­n­«°µ¡C

¦^¯Á¤Þ


¥Î SQL ¶}±Ò«ü©wªº Excel Sheet


±H¥óªÌ: ¼B½å²»

Visual Basic ¤¤¦pªG¨Ï¥ÎExcelÀÉ®×,·í°µData1ªºData Source¡A½Ð°Ý¬O§_¥i¥H¨Ï¥ÎSQL»yªk¨Ó¼W±j¨ä¬d¸ß¥\¯à,©Î¬OSQL¤@©w­n·f¡A °tAcessªº.MDBÀɤ~¯à¨Ï¥Î.¡H

¦Ñ©Çµª¡G

  1. SQL ¦b DAO ùتº¨Ï¥Î¡A´N¿ï¨ú¬d¸ß¨Ó»¡¡A¤£¤À¸ê®Æ¨Ó·½¡A¥u­n¯à¶}´N¯à¥Î¡C
  2. ¦ý¦b§ó·s©Î­×§ï¤W¡A¤£¦P¸ê®Æ¨Ó·½¦³¤£¦Pªº­­¨î¡C

±H¥óªÌ: ¼B½å²»

«Ü©êºp¦A¦¸¥´ÂZ§A,®Ú¾Ú§Aªº»¡ªk"SQL ¦b DAO ùتº¨Ï¥Î¡A¤£¤À¸ê®Æ¨Ó·½¡A¥u­n¯à¶}´N¯à¥Î",¦ý¬O§Ú¤@¦A¸ÕÅç¤@¦A®À§é,§Ú¬Æ¦Ü¨Ï¥Î¸ê®Æ®wºÞ²z­ûVisData¤¤ªºSQL¬d¸ß²£¥Í¾¹,¦ý¬OÁ`¬O±o¨ì¦p¤Uªº¿ù»~°T®§:

"The following Error occured: FROM¤l¥y¤¤ªº»yªk¿ù»~¡C¼Æ¥Ø:3131 Åã¥ÜData Access Errors ¶°¦Xª«¥ó¶Ü?" ¤U¦C¬O§Ú¸Õ¹LªºSQL³¯­z¥y(Excel ÀÉ®×:Piping.xls,Work sheet:Pipe,¨ä¤¤¦³¤@­Ófield:Price):

  1. SELECT * FROM Pipe$ WHERE Price = 150
  2. SELECT * FROM Pipe$ WHERE Price = 150
  3. Select * From Pipe$ Where (Pipe$.Price = '150' )
  4. Select Pipe$.* From Pipe$ Where (Pipe$.Price = '150' )
  5. Select * From Pipe$ Where Pipe$.Price = '150'

¦Ñ©Çµª¡G

Option Explicit
Dim Db As Database
Dim Rs As Recordset
Private Sub Form_Load()
Dim SqlString As String
    SqlString = "SELECT * FROM [Pipe$] WHERE »ù¿ú = 20"
'---------------------------------^^^^^^^^
'------------------------½Ð°O±o¥[ "["¡A"]" ²Å¸¹
    Set Db = OpenDatabase("c:\temp\book1.xls", False, False, "Excel 8.0;")
    Set Rs = Db.OpenRecordset(SqlString)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Rs.Close
    Db.Close
End Sub

¦^¯Á¤Þ


³]©w DBGrid Cell Unable


David Wong ¼¶¼g©ó¤å³¹

½Ð°Ý¦b VB 5.0 ªº DBGrid ¤¤¥i¥H³]©w¬Y¤@­Ó¯S©w Cell ªº enable ÄݩʶܡH

¦Ñ©Çµª¡G

  1. DbGrid ªº Column ª«¥ó¦³­Ó Locked ÄÝ©Ê¥i¥H³]©w¨¾¼g¡A¦ý¨º¬O¾ãÄæ³]©w¡A³æ¤@ Cell ¨ÃµL¬ÛÃöÄÝ©Ê¡C
  2. §Ú­Ì¥i¥H¥Îµ{¦¡¥[¥HÅܳq¡A´N¬O¦b­n³]©w Unable ªº Cell ¤W°O¿ý¨ä Col & Row ¡A¨Ã¦b BeforeColEdit ¨Æ¥ó¤¤¨ú®ø¨ä½s¿è°Ê§@¡A½d¨Ò¦p¤U¡G
    '´ú¸Õ¥»½d¨Ò½Ð©ó Form ¤W¥¬¸m Command1,Label1,Data1,DbGrid1
    Option Explicit
    Dim ColRec As Integer
    Dim RowRec As Integer
    '°O¦í¥Ø«e Cell ¦b¾î¶b¤ÎÁa¶b¦ì¸m
    Private Sub Command1_Click()
        ColRec = DBGrid1.Col
        RowRec = DBGrid1.Row
    End Sub
    Private Sub DBGrid1_BeforeColEdit(ByVal ColIndex As Integer, ByVal KeyAscii
    As Integer, Cancel As Integer)
        '¦pªG¥Ø«e Cell ¬O¦­¥ý³QÂê¦íªº¡A«h¨ú®ø½s¿è°Ê§@¡C
        If DBGrid1.Col = ColRec And DBGrid1.Row = RowRec Then
            Cancel = True
        End If
    End Sub
    Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal LastCol As
    Integer)
        'Åã¥Ü¥Ø«e Cell ½s¿èª¬ªp¡C
        If DBGrid1.Col = ColRec And DBGrid1.Row = RowRec Then
            Label1.Caption = "Àx¦s®æµLªk½s¿è"
        Else
            Label1.Caption = "Àx¦s®æ¥i¥H½s¿è"
        End If
    End Sub
    Private Sub Form_Load()
        Command1.Caption = "Âê¦íÀx¦s®æ"
        ColRec = -1
        RowRec = -1
    End Sub

¦^¯Á¤Þ


¤@ Recordset ¦h Form ¥Î


XXX ¼¶¼g©ó¤å³¹

DAO ¦p¦ó«Å§i(©Î³]©w) ¤@¦¸Recordset(DataBase)¡AÅý¥L¯à¦A¦h­ÓForm¤¤¨Ï¥Î,¤£¥Î¨C­ÓForm³£³]©w?

¦Ñ©Çµª¡G

¦^¯Á¤Þ


¦^­º­¶

1