ACCESS VBA笔记1

ACCESS VBA 笔记

VBA 语法

语法、函数
Select Case
	Select Case str1
        Case case1 
        	1=1
        Case case2,case3
        	1=1     
        Case Else
        	1=1  
    End Select
Do Until
	Do Until rst.EOF
  		1=1
    	rst.MoveNext
    Loop
On Error
     On Error Resume Next   '忽略错误	   
       
     On Error GoTo 跳转_Err			 
			' 。。。。。
		跳转_Exit:
		    Exit Function			
		跳转_Err:
		    MsgBox Error$
		    Resume 跳转_Exit
Split
	arr2 = Split(str1, ",") '把字符串str1,用 ","拆分成数组 arr2
    If UBound(arr2) > 0 Then
                num3 = UBound(arr2) - 1
               For i = 0 To num3
                    
               Next
      End If
    
    使用"/"操作符做除法运算时,如果其中之一是Double类型,那么结果就将是Double类型。所以,当2个Integer或者Single类型数值做除法运算时,如果想得到高精度的结果,就需要手工强迫其中之一转换为Double类型。 
自定义函数
			Public Function func1()
			    Dim arr(1 To 2) As String
			    ar02 = DLookup("单据编号", "单据表", "单据类型='" & Me.Text1 & "'")
			    If Len(ar02) > 0 Then
			   			func1 = arr    'func1数组为返回值
			    End If
			End Function


			Public Function func1(a,b,c)				    
			End Function
除法运算
	Dim a
    a = 20 Mod 13
    MsgBox "20除以13的余数为:" & a

窗体操作

1
        DCount("单据编号", "单据表", "单据编号='" & Me.Text1 & "'  ") ' 查询满足条件 单据编号= Me.Text1 记录的数量
        DLookup("单据编号", "单据表", "单据编号='" & Me.Text1 & "'  ") ' 查询满足条件 单据编号= Me.Text1 记录中 单据编号 的值

	HighlightForm Me 
    DoCmd.Maximize '窗口最大化
    DoCmd.SetOrderBy "ID DESC" '排序
    DoCmd.OpenReport "报表名称", ,acViewPreview, "报表筛选条件"
    DoCmd.OpenReport "报表名称", ,acViewPreview, "报表筛选条件", , acWindowNormal, OpenArgs  'OpenArgs传值参数
    DoCmd.OpenForm "窗体名称",
    DoCmd.OpenForm "窗体名称", acNormal, "筛选条件", , , acWindowNormal, OpenArgs  'OpenArgs传值参数
	DoCmd.OpenForm "SysFrmLogin", , , , , , OpenArgs  'OpenArgs传值参数
	
    Me.Requery
    Me.Refresh
	Me.Painting = False '关闭窗体刷新
	Me.Painting = True ' 
	
	Me.Text1 = "123"  
	Me.Combo1.RowSource = "SELECT 编号,名称 FROM 单据表 "
	Me.Text1.BackColor = RGB(240, 240, 240)  '黄绿红
    Me.Text1.ForeColor = RGB(240, 240, 240)
    Me.Text1.

你可能感兴趣的:(ACCESS VBA笔记1)