The blank column of the particular List Box based on query is not recognized as either empty or null

会有一股神秘感。 提交于 2020-01-05 07:11:49

问题


The Listbox: SearchList get data from the query: Machine_Search.So how it works is i input my Serial Number into the Search textbox and press the button search then select the record displayed on the SearchList. When the record is selected, i then press edit. The condition is that if the record that i search using Serial Number have empty field in the End_Date it will go on smoothly. However if the record that is search using Serial Number have a date in the End_Date it will prompt a msgbox and, close and open the form again. The issue lies at where it cannot detect if End_Date is null or empty and will prompt the msgbox regardless of the condition.

Table: Machine

Query: Machine_Search - It query the table:Machine where there is a form called: Machine_Load which fills half the field in the table and the other will be filled by Machine_Unload/

Form:Machine_Unload

Is there a way to solve this issue?

Private Sub cmdSearch_Click()
Dim check As String
    DoCmd.OpenQuery "Machine_Search"
    DoCmd.Close acQuery, "Machine_Search"
    SearchList.Requery

    If SearchList.ListCount = 0 Then
        MsgBox ("No records found.")
        DoCmd.Close
        DoCmd.OpenForm "Machine_Unload"
        Exit Sub
    End If

    Me.cmdEdit.Enabled = True
    Me.cmdSearch.Enabled = False
    Me.txtSN.Enabled = True
    Me.txtDate.Enabled = True
    Me.txtTime.Enabled = True
    Me.CheckTime.Enabled = True
    Me.ListSuccess.Enabled = True
    Me.txtOperator.Enabled = True
    Me.txtRemarks.Enabled = True
    Me.txtSearch.Enabled = False
    Me.txtSN.SetFocus
End Sub
Private Sub cmdEdit_Click()

On Error GoTo Err_cmdEdit_Click
Dim SN_Value As String
Dim Date_Value As String
    If Me.SearchList.ListIndex > -1 Then
        SN_Value = Me.SearchList.Value
        Date_Value = Me.SearchList.Column(5)

        If Not IsEmpty(Date_Value) Then
            MsgBox ("The Unload data for this Serial Number have been filled, Please confirm with cell leader.")
            DoCmd.Close
            DoCmd.OpenForm "Esagon_Unload"
            Exit Sub
        End If
    End If

    'check whether there exists data in list
    If Not (Me.SearchList.Recordset.EOF And Me.SearchList.Recordset.BOF) Then
        'get data to text box control
        With Me.SearchList.Recordset
            Me.txtSN = .Fields("Serial_Number")
            'store id of serial number in tag of txtSN in case id is modified
            Me.txtSN.Tag = .Fields("Serial_Number")
            'Disable button edit
            Me.cmdEdit.Enabled = False
            Me.cmdUpdate.Enabled = True

        End With
    End If

End_Err:
Exit Sub


Err_cmdEdit_Click:
MsgBox ("Select the Serial Number." & vbCrLf & "Please try again and click on the Serial Number below.")
DoCmd.Close
DoCmd.OpenForm "Machine_Unload"
Resume End_Err

End Sub
SELECT Machine.Serial_Number, Machine.End_Date, Machine.End_Time, Machine.End_System_Time, Machine.End_Operator, Machine.Success, Machine.End_Remarks
FROM Machine
WHERE (((Machine.Serial_Number)=[Forms]![Machine_Unload]![txtSearch]));

回答1:


IsEmpty is not for this usage. Try:

If Not IsNull(Date_Value) Then

or:

If Nz(Date_Value) <> "" Then


来源:https://stackoverflow.com/questions/59384657/the-blank-column-of-the-particular-list-box-based-on-query-is-not-recognized-as

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!