以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]数据填充的问题?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=25250)

--  作者:lsf5138
--  发布时间:2012/11/5 8:13:00
--  [求助]数据填充的问题?

铵钮代码如下:

If _UserGroup = "物流部" Then
    With Tables("水洗")
        If .Current IsNot Nothing Then
            If Tables("水洗").Current("确认")=False   
                With e.Form
                    If .Controls("Label5").Text = "OK" Then  \'如果信息完善,则新建令号
                        Dim Filter As String
                        With e.Form.Controls("TextBox4")
                            If .Value IsNot Nothing Then
                                Filter = "生产条码 = \'" & .Value & "\'"
                            End If
                        End With
                        If Filter > "" Then
                            Tables("织机生产").Filter = Filter
                        End If

                            With Tables("织机生产")
                                If .Current IsNot Nothing Then

                                    Dim tr As Row = Tables("织机生产").Current()
                                    tr("水洗批次") = .Controls("TextBox1").Value
                                    tr("水洗_载货日期") = .Controls("DateTimePicker2").Value
                                    tr("水洗_单位") = .Controls("ComboBox1").Value
                                    tr.Save()

                                Else
                                    MessageBox.show("没有这条记录!")
                                End If
                            End With

                    End If
                End With
            Else
                MessageBox.show("本批次已确认完成,不可再添加!")
            End If
        Else
            MessageBox.show("目录表没有记录!")
        End If
    End With
Else
    MessageBox.show("物流部才能操作!")
End If

原代码筛选后记录如果为空,再执行数据填充会报错。我就在筛选后加个记录为空不执行的代码,不知为什么加不了,会报错!


--  作者:狐狸爸爸
--  发布时间:2012/11/5 8:25:00
--  

别用那么多的With,你把自己给With糊涂了,只有连续使用的时候,用With比较合适,而且嵌套的With,生效的只是最里头一个。

 

If _UserGroup = "物流部" Then
    With Tables("水洗")
        If .Current IsNot Nothing Then
            If Tables("水洗").Current("确认")=False
                    If e.Form.Controls("Label5").Text = "OK" Then  \'如果信息完善,则新建令号
                        Dim Filter As String
                        With e.Form.Controls("TextBox4")
                            If .Value IsNot Nothing Then
                                Filter = "生产条码 = \'" & .Value & "\'"
                            End If
                        End With
                        If Filter > "" Then
                            Tables("织机生产").Filter = Filter
                        End If
                        With Tables("织机生产")
                            If .Current IsNot Nothing Then
                               
                                Dim tr As Row = Tables("织机生产").Current()
                                tr("水洗批次") = e.Form.Controls("TextBox1").Value
                                tr("水洗_载货日期") = e.Form.Controls("DateTimePicker2").Value
                                tr("水洗_单位") = e.Form.Controls("ComboBox1").Value
                                tr.Save()
                            Else
                                MessageBox.show("没有这条记录!")
                            End If
                        End With
                    End If
            Else
                MessageBox.show("本批次已确认完成,不可再添加!")
            End If
        Else
            MessageBox.show("目录表没有记录!")
        End If
    End With
Else
    MessageBox.show("物流部才能操作!")
End If