首页 > 代码库 > access的一些简单操作

access的一些简单操作

Option Compare Database

 

Private sqladdress As String

Private PrintSavebool As Boolean

 

‘程序初始化
Private Sub Init()
sqladdress = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=U:\2.Personal\Ye\log.mdb;Persist Security Info=False"

PrintSavebool = False

 


End Sub

‘判断是是否存在在数据库中
‘2014.09.02

‘用于查看

Private Sub CheckOrder(ordernumber As String)

PrintSavebool = False

On Error GoTo ErrHandle

Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Set rs = Nothing

SQL = "select [DT] from [PrintLog] where [ORDERID]=" + "‘" + ordernumber + "‘"

conn.Open sqladdress
rs.Open SQL, conn


If Not rs.EOF Then
‘ If MsgBox("order number:" + ordernumber + "Print had Done,Time:" + CStr(rs!DT) + " continue?", vbYesNo) = vbYes Then
‘Else

‘Cancle = True

‘End If


MsgBox "order number:" + ordernumber + "Print had Done,Time:" + CStr(rs!DT) + " continue?"

PrintSavebool = False
Else

PrintSavebool = True
End If
rs.Close
Set rs = Nothing


Exit Sub


‘错误处理
ErrHandle:
MsgBox "check log database error"

Exit Sub

End Sub

 

‘把打印记录放到数据库中
‘2014.09.02

Public Sub SaveOrder(ordernumber As String)

If PrintSavebool = False Then

Exit Sub
End If


On Error GoTo ErrHandle

Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Set rs = Nothing

SQL = "insert into [PrintLog]([ORDERID],[DT]) values (" + "‘" + ordernumber + "‘" + "," + "‘" + CStr(Now) + "‘" + ")"
conn.Open sqladdress
rs.Open SQL, conn

Set rs = Nothing
Exit Sub


‘错误处理
ErrHandle:
MsgBox "record log error"
Exit Sub

End Sub

‘Private Sub Report_Page()

‘‘Call Log(Label0.Caption)
‘End Sub
‘在打印


Public Sub Log(ordernumber As String)

Call Init

Call CheckOrder(ordernumber)

Call SaveOrder(ordernumber)

 

End Sub

access的一些简单操作