You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel 2017表单Add Details文本框留存上次输入问题求助

工单查询表单文本框残留旧内容问题

我用Excel 2017制作了一个工单查询表单,用户输入特定工单编号后可查找对应记录并添加工作详情。当匹配到目标记录时,表单会加载该记录的PO#、零件号、序列号及当前状态,但Add Details文本框会显示上次输入的内容,这不符合预期。

最初我以为是代码读取了对应记录的第11列(K列)数据,但更换工单编号后问题依旧,且该记录中并无对应的“Begin Work -”注释,说明问题另有原因。

表单打开时所有字段均为空,代码逻辑看似正常(如下所示)。Add Details字段对应工作表ws2的“Details”列,代码中该文本框关联Cells(i,11).Value,但查找代码并未主动读取该列内容。

ws2.Activate 'Move to Open Worksheet

'***** CHECK FOR DUPLICATE ENTRIES WORK THIS WITH SEARCH CODE*****

Range("A" & Rows.Count).End(xlUp).Offset(1).Select
iRow = ActiveCell.Row
lastRow = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row

InitFind: 'Find Matching Work Order number to Form Input
For i = 3 To lastRow 'SEARCH FOR DUPLICATE WO & PO NUMBERS
    wo = Cells(i, 3).Value
    If WN = wo Then
        po = Cells(i, 4).Value
        pn = Cells(i, 5).Value
        sn = Cells(i, 6).Value
        st = Cells(i, 2).Value
        
        Me.txt_po.Value = po
        Me.txt_pn.Value = pn
        Me.txt_sn.Value = sn
        Me.cmb_Stat.Value = st
        YN = MsgBox("Is this the record that you want?", vbYesNo)
            If YN = vbYes Then
                Me.txt_Detail.Value = ""
                Me.cmb_Stat.SetFocus
                Me.cmd_More.Visible = True
                Me.cmd_CloseWO.Visible = True
                Me.cmd_Update.Visible = True
                Me.cmd_Find.Visible = False
                
                    If Me.txt_pn.Value = "31406-002" Or Me.txt_pn.Value = "31406-003" Then
                        GoTo Batt
                    ElseIf Me.txt_pn.Value = "40-424" Or Me.txt_pn.Value = "40-423" Then
                        GoTo Wheel
                    ElseIf Me.txt_pn.Value = "40-478" Or Me.txt_pn.Value = "40-479" Then
                        GoTo Wheel
                    ElseIf Me.txt_pn.Value = "3-1501" Then
                        GoTo Wheel
                    Else
                        GoTo Update
                    End If
            Else
                Me.txt_WN.Value = ""
                Me.txt_po.Value = ""
                Me.txt_pn.Value = ""
                Me.txt_sn.Value = ""
                Me.cmb_Stat.Value = ""
                Me.txt_Detail.Value = ""
                Me.txt_WN.SetFocus
                Exit Sub
            End If
    End If
Next i

MsgBox "Searched through all open WO's, No match found. Re-enter Work Order number or click Exit."
Me.txt_WN.Value = ""
Me.txt_WN.SetFocus
Exit Sub

目前的临时解决方法是在用户点击消息框的“Yes”时强制设置Me.txt_Detail.Value = "",但文本框仍会先显示上次输入的内容,可能造成用户困惑。该问题仅在点击“Find”按钮触发宏后出现。

我尝试过在表单关闭保存数据前重置该文本框(代码如下),但无效;也调整过Me.txt_Detail.Value = ""的代码位置,均无法解决问题。已确定问题出在InitFind到YN消息框的代码段中,但无法定位具体原因。

FinishSub:
Me.txt_Detail.Value = ""
ws1.Activate
Unload Me

我还仔细检查了文本框属性,未发现异常;尝试设置其Value属性为"",结果只是在文本框中显示引号。

内容的提问来源于stack exchange,提问作者Vincent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 01:47:56