| 
Option Compare Database
Option Explicit
Function sam0601()
    Dim t1 As Integer
    Dim t2 As Double
    Dim t3 As String
    Dim t4 As Date
    t1 = 1
    t2 = 5.25
    t3 = "abc"
    t4 = Now()
    DoCmd.RunSQL ("insert into tmp values(" & t1 & "," & t2 & ",'" & t3 & "',#" & t4 & "#)")
    DoCmd.RunSQL ("insert into tmp values(2,3.33,'def',#11/8/01 7:43:59 PM #)")
End Function
 Function sam0602(Optional t1 As Integer, Optional t2 As Double, Optional t3 As String, Optional t4 As Date)
    If Not IsNull(t1) And IsNumeric(t1) Then t1 = 22
    If Not IsNull(t2) And IsNumeric(t2) Then t2 = 22.2222
    If Not IsNull(t3) And Len(t3) = 0 Then t3 = "def"
    If Not IsNull(t4) And IsDate(t4) Then t4 = Now()
    DoCmd.RunSQL ("insert into tmp values(" & t1 & "," & t2 & ",'" & t3 & "',#" & t4 & "#)")
End Function
 Function sam0603()
    Dim t1 As Integer
    Dim t2 As Double
    Dim t3 As String
    Dim t4 As Date
    Dim i As Integer
    Randomize
    For i = 1 To 5
        t1 = Int((Rnd * 10) + 1)
        t2 = Rnd * 10
        t3 = Chr(Int((Rnd * 26) + 65)) & Chr(Int((Rnd * 26) + 65)) & Chr(Int((Rnd * 26) + 65))
        t4 = Now()
        DoCmd.RunSQL ("insert into tmp values(" & t1 & "," & t2 & ",'" & t3 & "',#" & t4 & "#)")
    Next
End Function
 Function sam0604()
    Dim t1 As Integer
    Dim t2 As Double
    Dim t3 As String
    Dim t4 As Date
    Dim i, max As Integer
    Dim dbs As Database
    Dim rst As Recordset
    Dim strSQL As String
    Set dbs = CurrentDb()
    strSQL = "SELECT * FROM [tmp];"
    Set rst = dbs.OpenRecordset(strSQL)
    max = 0
    rst.MoveFirst
    While (Not (rst.EOF))
        If rst!tmpseq > max Then max = rst!tmpseq
        rst.MoveNext
    Wend
    rst.Close
    dbs.Close
    Randomize
    For i = 1 To 5
        max = max + 1
        t1 = max
        t2 = Rnd * 10
        t3 = Chr(Int((Rnd * 26) + 65)) & Chr(Int((Rnd * 26) + 65)) & Chr(Int((Rnd * 26) + 65))
        t4 = Now()
        DoCmd.RunSQL ("insert into tmp values(" & t1 & "," & t2 & ",'" & t3 & "',#" & t4 & "#)")
    Next
End Function
 |