本程序有一菜单开始,里面有查询,删除,修改,添加,程序不一一列出,只写出基本的过程,连接数据库采用标准模块:
'Public publicstr As String
Public conn As ADODB.Connection
Public rs As ADODB.Recordset
Public Sub main() '数据库连接共享函数
Set conn = New ADODB.Connection
conn.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=plgl;Initial Catalog=plgl"
'publicstr = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=plgl;Initial Catalog=plgl" '共享连接字符串
main_pfm.Show
End Sub
添加程序:
Set rs = New ADODB.Recordset
If Trim(Text1(0).Text) = "" Then
smeg = "配方号不能为空!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(0).SetFocus
Else
If Not IsNumeric(Text1(0).Text) Then
smeg = "A添加剂非数字!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(0).Text = ""
Text1(0).SetFocus
Else
If Trim(Text1(1).Text) = "" Then
smeg = "配方名称不能为空!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(1).SetFocus
Else
If Trim(Text1(2).Text) = "" Then
smeg = "A添加剂不能为空!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(2).SetFocus
Else
If Not IsNumeric(Text1(2).Text) Then
smeg = "A添加剂非数字!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(2).Text = ""
Text1(2).SetFocus
Else
If Trim(Text1(3).Text) = "" Then
smeg = "B添加剂不能为空!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(3).SetFocus
Else
If Not IsNumeric(Text1(3).Text) Then
smeg = "B添加剂非数字!!!"
MsgBox smeg, vbOKCancel + vbExclamation, "警告"
Text1(3).Text = ""
Text1(3