这个是单表的查询窗体 语句在下面 里面有错误 Public s As String Dim a2 As String, a3 As String, a4 As String
Private Sub com1_Click() If text1.Value = "" Or cb2.Value = "" Or cb3.Value = "" Or text2.Value = "" Then MsgBox ("输入的全部值不可为空!") Else text2.SetFocus s = s + " AND " text2.Text = s com1.Enabled = False com2.Enabled = False com3.Enabled = True End If End Sub
Private Sub com2_Click() If text1.Value = "" Or cb2.Value = "" Or cb3.Value = "" Or text2.Value = "" Then MsgBox ("输入的全部值不可为空!") Else text2.SetFocus s = s + " OR " text2.Text = s com1.Enabled = False com2.Enabled = False com3.Enabled = True End If
End Sub
Private Sub com3_Click() cb2.SetFocus a2 = cb2.Text cb3.SetFocus a3 = cb3.Text text1.SetFocus a4 = text1.Text If a4 = "" Or a2 = "" Or a3 = "" Then MsgBox ("输入的全部值不可为空!") Else If cb2.Value = "采购员编号" Then 's = s + " " + a2 + " " + a3 + " " + "'" + "*" + a4 + "*" + "'" s = s + a2 + a3 + a4 ElseIf cb3 = "LIKE" Or cb3 = "NOT LIKE" Then s = s + " " + a2 + " " + a3 + " " + "'" + "*" + a4 + "*" + "'"
Else s = s + " " + a2 + " " + a3 + " " + "'" + a4 + "'" End If
text2.SetFocus text2.Text = s com1.Enabled = True com2.Enabled = True com3.Enabled = True End If
End Sub
Private Sub com4_Click() l1.RowSource = "SELECT * FROM 采购员资料表 WHERE " + s + ";"
If text2.Value = "" Then MsgBox ("请先按ADD键") End If
End Sub
Private Sub com5_Click()
s = "" text2.Value = "" text1.Value = "" cb2.Value = "" cb3.Value = "" l1.Value = "" l1.RowSource = "" com1.Enabled = False com2.Enabled = False
End Sub
Private Sub Form_Load() com1.Enabled = False com2.Enabled = False com3.Enabled = True
End Sub
Private Sub l1_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub 主体_Click()
End Sub
Private Sub 关闭窗体_Click() On Error GoTo Err_关闭窗体_Click
DoCmd.Close
Exit_关闭窗体_Click: Exit Sub
Err_关闭窗体_Click: MsgBox Err.Description Resume Exit_关闭窗体_Click End Sub
这个是多表的查询窗体图 多表的语句现在就查一个判断字段类型的函数了
Public s As String Dim a2 As String, a3 As String, a4 As String
Private Sub com1_Click() If text1.Value = "" Or cb2.Value = "" Or cb3.Value = "" Or text2.Value = "" Then MsgBox ("输入的全部值不可为空!") Else text2.SetFocus s = s + " AND " text2.Text = s com1.Enabled = False com2.Enabled = False com3.Enabled = True End If End Sub
Private Sub com2_Click() If text1.Value = "" Or cb2.Value = "" Or cb3.Value = "" Or text2.Value = "" Then MsgBox ("输入的全部值不可为空!") Else text2.SetFocus s = s + " OR " text2.Text = s com1.Enabled = False com2.Enabled = False com3.Enabled = True End If
End Sub
Private Sub com3_Click() cb2.SetFocus a2 = cb2.Text cb3.SetFocus a3 = cb3.Text text1.SetFocus a4 = text1.Text If a4 = "" Or a2 = "" Or a3 = "" Then MsgBox ("输入的全部值不可为空!") Else If cb2.Value = "采购员编号" Or cb2.Value = "仓库编号" Or cb2.Value = "库存量" Then 's = s + " " + a2 + " " + a3 + " " + "'" + "*" + a4 + "*" + "'" s = s + a2 + a3 + a4 ElseIf cb3 = "LIKE" Or cb3 = "NOT LIKE" Then s = s + " " + a2 + " " + a3 + " " + "'" + "*" + a4 + "*" + "'"
Else s = s + " " + a2 + " " + a3 + " " + "'" + a4 + "'" End If
text2.SetFocus text2.Text = s com1.Enabled = True com2.Enabled = True com3.Enabled = True End If
End Sub
Private Sub com4_Click() l1.RowSource = "SELECT * FROM 查询1 WHERE " + s + ";"
If text2.Value = "" Then MsgBox ("请先按ADD键") End If
End Sub
Private Sub com5_Click()
s = "" text2.Value = "" text1.Value = "" cb2.Value = "" cb3.Value = "" l1.Value = "" l1.RowSource = "" com1.Enabled = False com2.Enabled = False
End Sub
Private Sub Form_Load() com1.Enabled = False com2.Enabled = False com3.Enabled = True
End Sub
Private Sub l1_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub 主体_Click()
End Sub
Private Sub 关闭窗体_Click() On Error GoTo Err_关闭窗体_Click
DoCmd.Close
Exit_关闭窗体_Click: Exit Sub
Err_关闭窗体_Click: MsgBox Err.Description Resume Exit_关闭窗体_Click End Sub