accessvba源碼
1. 請教Access中的VBA程序代碼
添加 DoCmd 對象的 Quit 方法是為了提供在 Microsoft Access for Windows 95 的 Visual Basic 代碼中執行 Quit 操作的後向兼容性。建議使用 Application 對象的 Quit 方法來代替。
2. ACCESS中VBA代碼問題
你好象對ACCESS中VBA的語法不太了解。你需要主、子窗體聯動,不需要這么麻煩,分別設置主、子窗體的記錄源,然後在子窗體的「鏈接主欄位」和「鏈接子欄位」的兩個屬性中設置一下關聯的欄位就行了。
3. ACCESS資料庫VBA代碼
第一題 N的最終值相當於經過了I和J的3*4次循環,因為每次循環都只加了1,所以就等於12
第二題 S的值每次循環都只加1,所以只要知道了循環的次數就知道S的值。第一次循環後I的值為1*2=2;第二次循環後I的值變為2+2=4,因為步徑值STEP是2,然後再4*2=8;第三次循環後I的值變為8+2=10,然後再10*2=20。因為循環了三次,所以S的值為3,I的值為20.
4. access VBA代碼
語句本身沒有問題,問題出在不是操作查詢上。我試過,如果是操作查詢,類似的語句是可以執行的。如:docmd.Runsql
"INSERT
INTO
表2
(
欄位a,
欄位B
)
SELECT
DISTINCT
表1.欄位a,
定額.欄位B
FROM
表1
WHERE
(((表1.欄位a)="
&
"
'"
&
tuhao
&
"'
"
&
"))
ORDER
BY
表1.欄位B"
建議換方式查詢。
5. access vba 編程 請高手發個編程代碼。謝謝。謝謝、
'計算1到100的所有偶數的和
Function sum100() As Integer
Dim i As Integer
Dim iSum As Integer
iSum = 0
For i = 2 To 100 Step 2
iSum = iSum + i
Next i
sum100 = iSum
MsgBox (iSum)
iSum = 0
i = 2
While (i <= 100)
iSum = iSum + i
i = i + 2
Wend
MsgBox (iSum)
iSum = 0
i = 2
Do Until (i > 100)
iSum = iSum + i
i = i + 2
Loop
MsgBox (iSum)
sum100 = iSum
End Function
'計算出1至200能被3整除的所有數, 並統計個數
Function sum200d3() As Integer
Dim i As Integer
Dim iCount As Integer
Dim sNum As String
iCount = 0
sNum = "1至200能被3整除的所有數:"
For i = 1 To 200
If i Mod 3 = 0 Then
sNum = sNum + Str(i) + ", "
iCount = iCount + 1
End If
Next i
MsgBox (sNum + "個數為:" + Str(iCount))
End Function
'附言: 小鬼, 作業要自己完成啊!
6. Excel調用ACCESS的VBA代碼怎麼寫
提供一種在EXCEL使用代碼,連接ACCESS,取得數據的方法,看是不是你要的東西:
SubAC()
DimcnnAsNewConnection
DimrsAsNewRecordset
DimsqlAsString
DimqxAsString
qx="金牛"
cnn.Open"Provider=Microsoft.Ace.OleDB.12.0;dataSource="&ThisWorkbook.Path&"資料庫.accdb"
sql="select*from[宏站]where區域='"&qx&"'"
'('"&qx&"'")括弧里這段有點BT,一定要這樣寫才行。
rs.Opensql,cnn
[a1].CopyFromRecordsetrs
EndSub
7. 求access加vba的倉儲管理程序,要源代碼
更詳細的留個郵箱
Attribute VB_Name = "base"
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function BackupData Lib "storage.dll" (ByVal filename As String, ByVal backname As String) As Long
Public Declare Function ResumeData Lib "storage.dll" (ByVal filename As String, ByVal backname As String) As Long
Public Declare Function GetBit Lib "storage.dll" (ByVal bit As Long, ByVal index As Integer) As Integer
Public Declare Function GetBits Lib "storage.dll" (ByVal bit As String, ByVal l As Integer) As Long
Public Declare Function ShowHelp Lib "storage.dll" (ByVal hwnd As Long, ByVal chmname As String, ByVal htmlname As String) As Long
Public Declare Function AddWndMsg Lib "storage.dll" (ByVal hwnd As Long, ByVal msg As Long, ByVal procaddress As Long) As Long
Public Declare Function ClearPrintData Lib "FxPrint.dll" () As Integer
Public Declare Function SetPrintDataWidth Lib "FxPrint.dll" (ByVal width As Integer) As Integer
Public Declare Function AddPrintData Lib "FxPrint.dll" (ByVal data As String) As Integer
Public Declare Function ShowPrint Lib "FxPrint.dll" (ByVal title As String) As Integer
Public Declare Function SaveToFile Lib "FxPrint.dll" () As Integer
Public fMainForm As frmMain '主窗口句柄
Public DataPath As String '資料庫路徑
Public DataConnectString As String '資料庫連接源字元串
Public UserName As String '用戶名
Public UserPas As String '用戶密碼
Public Purview As Long '操作許可權
Public 許可權類別(16) As Integer '17種許可權類別
Public Function ShowPrintDlg(ByVal ado As Adodc, ByVal title As String)
'清除以前的列印數據
ClearPrintData
Dim count As Integer
On Error GoTo quit:
count = ado.Recordset.Fields.count
If count <= 0 Then
MsgBox "沒有需列印的數據", vbInformation
Exit Function
End If
'設置列印列寬度
SetPrintDataWidth count
'保存當前位置的狀態pos
Dim pos As Long
pos = ado.Recordset.AbsolutePosition
'移到記錄最前面
ado.Recordset.MoveFirst
Dim i As Integer
'寫入眉頭
For i = 0 To count - 1
AddPrintData ado.Recordset.Fields(i).name
Next
'寫入數據
While ado.Recordset.EOF = False
For i = 0 To count - 1
If ado.Recordset.Fields(i).ActualSize > 0 Then
AddPrintData ado.Recordset.Fields(i).Value
Else
AddPrintData ""
End If
Next
ado.Recordset.MoveNext
Wend
'恢復以前的記錄
ado.Recordset.MoveFirst
If pos > 1 Then ado.Recordset.Move pos - 1
ShowPrint title
Exit Function
quit:
MsgBox "沒有列印數據或列印數據未初始化!", vbInformation
End Function
Public Function ShowHelpWnd(index As Long)
If index = 0 Then
ShowHelp fMainForm.hwnd, App.HelpFile, ""
Else
Dim htmlname As String
htmlname = "倉庫管理系統.htm/#"
Dim v As String
v = LTrim(Str(index))
Dim i As Integer
For i = 1 To Len(v)
htmlname = htmlname + Mid(v, i, 1)
If i <> Len(v) Then htmlname = htmlname + "_"
Next
ShowHelp fMainForm.hwnd, App.HelpFile, htmlname
End If
End Function
'屏蔽flash右鍵彈出菜單
Public Function FlashNoRButton(ByVal hwnd As Long, ByVal msg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
FlashNoRButton = 1
End Function
'刪除記錄中的所有數據
Public Function DeleteRecordData(Re As Recordset)
If Re.RecordCount <= 0 Then Exit Function
Re.MoveFirst
While Re.EOF = False
Re.Delete
Re.MoveFirst
Wend
End Function
Sub Main()
'檢測是否已運行
If App.PrevInstance Then
MsgBox App.title + " 已運行!"
End
End If
'初始化資料庫文件路徑
DataPath = App.Path + "\storage.mdb"
DataConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataPath + ";Persist Security Info=False" + ";Jet OLEDB:Database Password=prowind"
'啟動起始屏
frmSplash.Show vbModal
'啟動登陸對話框
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.OK Then
'登錄失敗,退出應用程序
End
End If
Unload fLogin
'啟動主窗口
Set fMainForm = New frmMain
fMainForm.Show
End Sub