【我的订单】
这是用户中心的一个子窗体:数据来源是tab_salelist,注意:那个大写的USERID就是当初我们命名的那个公用变量,他一直在发挥着作用。
Private Sub Form_Load()
Dim sqlstr As String
If USERID = "" Then
MsgBox "你还未登录,不能查看订单"
DoCmd.Close acForm, "frm_userhome"
Else
sqlstr = "select listid,lstate,sdate,mcount from tab_salelist where uid=" & USERID
Me.Child4.Form.RecordSource = sqlstr
End If
End Sub
删除按钮就一句话:
Private Sub Command12_Click()
If Me.lstate <> "未处理" Then
MsgBox "你的订单已经开始受理,不能删除了"
Else
DoCmd.RunSQL ("delete * from tab_salelist where listid='" & Me.listid & "'")
End If
End Sub
还有一个按钮时“明细”:先设定了订单明细的数据源,然后再打开它。其实这些复杂的sql语句我都是先在查询中设计好了,然后再复制到vba中来,对于其中的一些变量,比如用户id,就先用数字直接写入:然后再把它替换出来就行了,比如下面的这段sql是这样来的:把两张图合起来看:
Private Sub Command13_Click()
Dim myid As String
myid = Me.listid
Dim sqlstr As String
sqlstr = "SELECT tab_salerecord.uid, tab_Pinfo.pname, tab_Pinfo.pkind, tab_Pinfo.price, " & _
"tab_Pinfo.lprice, tab_salerecord.pcount, [lprice]*tab_salerecord!pcount AS msum, tab_salerecord.ID, tab_salerecord.yn " & _
"FROM tab_Pinfo INNER JOIN tab_salerecord ON tab_Pinfo.id = tab_salerecord.pid " & _
"WHERE tab_salerecord.lid='" & myid & "'"
[Forms]![frm_userhome]![Child5].[Form].RecordSource = sqlstr
[Forms]![frm_userhome]![Label16].Caption = myid
[Forms]![frm_userhome]!选项卡控件7.Pages(1).SetFocus
End Sub
[此贴子已经被作者于2006-8-10 1:44:20编辑过]
|