VB 新手,从网上找了一个源码是我需要用到的,但是生成EXE的时候提示没有定义,错误第一句在黄色底色那里。

 

 

 

Option Explicit
Dim Cnn As ADODB.Connection
Dim Res As ADODB.Recordset
Dim SQL As String
Dim DB_Path As String
Private Sub ReadDataFromDB()
DB_Path = App.Path + "\DataBase\SN_Tab.mdb"
SQL = "select * from sn"
Set Cnn = New ADODB.Connection
Set Res = New ADODB.Recordset
Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & DB_Path & ";Persist Security Info=False"
Res.Open SQL, Cnn, adOpenKeyset, adLockReadOnly
Set Grid.DataSource = Res                ‘提示没有定义’  这个是哪里错了?
Res.Close
Cnn.Close
Set Res = Nothing
Set Cnn = Nothing
RowID
End Sub
Private Sub RowID()
Dim i As Long
With Grid
For i = 1 To .Rows - 1
.TextMatrix(i, 0) = i
Next i
End With
End Sub
Private Sub AdjustGrid()
Dim i As Integer
For i = 0 To 8
Grid.ColDataType(i) = flexDTString
Grid.ColAlignment(i) = flexAlignLeftCenter
Next i
Grid.ColWidth(0) = 800
Grid.ColWidth(7) = 1500
Grid.ColWidth(8) = 4000
For i = 1 To 6
Grid.ColWidth(i) = (Grid.Width - 6300) / 6
Next i
End Sub
Private Sub AdjustControl()
With Grid
.Left = 15
.Top = Picture_Title.Height + Picture_ToolList.Height + 15
.Width = Me.Width - 30
.Height = Me.Height - .Top - 15
End With
With Picture_Close
.Left = Me.Width - .Width
End With
With Picture_Max
.Top = Picture_Normal.Top
.Left = Picture_Close.Left - 15 - .Width
Picture_Normal.Left = .Left
End With
With Picture_Min
.Left = Picture_Max.Left - 15 - .Width
End With
AdjustGrid

End Sub
Private Sub SizeFormH()
Dim hTaskBar As Long
hTaskBar = FindWindow("Shell_TrayWnd", vbNullString)
Debug.Print hTaskBar
Dim RC As RECT
Dim i As Long
i = GetWindowRect(hTaskBar, RC)
Dim taskheight As Long
taskheight = RC.Bottom - RC.Top '任务栏高度
i = GetWindowRect(GetDesktopWindow, RC)
Dim maxwidth As Long
Dim maxheight As Long
maxwidth = RC.Right - RC.Left '获取屏幕宽度
maxheight = RC.Bottom - RC.Top - taskheight '屏幕高度-任务栏高度
LockWindow Me.hwnd, , , maxwidth, maxheight
End Sub
Private Sub Form_Load()
Dim IStyle As Long, i As Integer
IStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
IStyle = IStyle Or WS_SYSMENU Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
SetWindowLong Me.hwnd, GWL_STYLE, IStyle
lOldproc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WndProc)
SizeFormH
AdjustControl
ReadDataFromDB
End Sub

Private Sub Form_Resize()
If Me.WindowState <> 1 Then AdjustControl
End Sub

Private Sub Form_Unload(Cancel As Integer)
Form_Main.Enabled = True
End Sub

Private Sub Picture_Close_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture_Close
If X > 0 And X < .Width And Y > 0 And Y < .Height Then
SetCapture .hwnd
If .BackColor <> &H5D2& Then .BackColor = &H5D2&
Else
ReleaseCapture
If .BackColor <> &H0& Then .BackColor = &H0&
End If
End With
End Sub

Private Sub Picture_Close_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Unload Me
End Sub

Private Sub Picture_Max_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture_Max
If X > 0 And X < .Width And Y > 0 And Y < .Height Then
SetCapture .hwnd
If .BackColor <> &HDD9300 Then .BackColor = &HDD9300
Else
ReleaseCapture
If .BackColor <> &H0& Then .BackColor = &H0&
End If
End With
End Sub

Private Sub Picture_Max_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.WindowState = 2
Picture_Normal.Visible = True
Picture_Max.Visible = False
Picture_Max.BackColor = &H0
End If
End Sub

Private Sub Picture_Min_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture_Min
If X > 0 And X < .Width And Y > 0 And Y < .Height Then
SetCapture .hwnd
If .BackColor <> &HDD9300 Then .BackColor = &HDD9300
Else
ReleaseCapture
If .BackColor <> &H0& Then .BackColor = &H0&
End If
End With
End Sub

Private Sub Picture_Min_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Me.WindowState = 1: Picture_Min.BackColor = &H0
End Sub

Private Sub Picture_Normal_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture_Normal
If X > 0 And X < .Width And Y > 0 And Y < .Height Then
SetCapture .hwnd
If .BackColor <> &HDD9300 Then .BackColor = &HDD9300
Else
ReleaseCapture
If .BackColor <> &H0& Then .BackColor = &H0&
End If
End With
End Sub

Private Sub Picture_Normal_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.WindowState = 0
Picture_Max.Visible = True
Picture_Normal.Visible = False
Picture_Normal.BackColor = &H0
End If
End Sub

Private Sub Picture_Title_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

Private Sub Picture_ToolList_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture_Title_MouseDown Button, Shift, X, Y
End Sub