Results 1 to 2 of 2
  1. #1
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26

    Question Dlookup problem - Invalid use of Null

    Hello, in my form i have 2 List box, one call "listPilih" and one more call "listSofProduct". Then i have click button called "addBtn", and code for this button is :
    Code:
    Private Sub addBtn_Click()Dim strSql As String
    Dim checkValue As Integer
    
    'Error on below
    checkValue = DLookup("idProduct", "tblSofProduct", "[idProduct]=" & Me.listPilih)
    
    
    If Me.listPilih.ListIndex < 0 Then
    
    
    MsgBox " Please select invoice, then choice which one product to add on S.O.F", vbCritical, "ERROR"
    
    
    Else
        If Me.listPilih = checkValue Then
    
    
        MsgBox "Sorry,Product already in the list", vbCritical, "ERROR"
    
    
        Else
    
    
    'SQL string to tblSofProduct
    
    
        strSql = " INSERT INTO tblSofProduct " _
                & "(idSof, idProduct) VALUES " _
                & "(" & Forms!formListSof!idSof & ", " & Me.listPilih & ");"
    
    
    
    
        CurrentDb.Execute strSql, dbFailOnError
    
    
        Me.listSofProduct.Requery
    
    
    End If
    End If
    End Sub
    So when user click addBtn, product from "listPilih' will copy and insert to "listSofProduct". But user cannot insert same product to "listSofProduct".

    When code excute, have error : Invalid use of Null...

    How to solved this problem? i need help... Thank you

    p/s: Sorry for bad english... hehehe

  2. #2
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26
    Hello, i have resolved this problem... i just change from Dlookup to Dcount... Because Dlookup does return Null value

    This is my code, hope can help who have a same problem...

    Code:
    Private Sub addBtn_Click()
    Dim strSql As String
    Dim checkValue As Integer
    
    
    'Check is user select from list or not
    
    
    If Me.listPilih.ListIndex < 0 Then
    
    
    MsgBox " Please select invoice, then choice which one product to add on S.O.F", vbCritical, "ERROR"
    
    
    Else
    
    
        ' Run dcount here
        
        checkValue = DCount("idProduct", "tblSofProduct", "[idProduct]=" & Me.listPilih)
        If checkValue = 0 Then
    
    
        'SQL string is here
    
    
            strSql = " INSERT INTO tblSofProduct " _
                & "(idSof, idProduct) VALUES " _
                & "(" & Forms!formListSof!idSof & ", " & Me.listPilih & ");"
    
    
            
            'Run SQL
            CurrentDb.Execute strSql, dbFailOnError
            
            'Requery list box
            
            Me.listSofProduct.Requery
    
    
        
        'If Dcount return 1
        
        ElseIf checkValue = 1 Then
    
    
            MsgBox "Sorry,Product already in the list", vbCritical, "ERROR"
            
        Exit Sub
        
        End If
    
    
    End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error 94: Invalid Use of Null
    By athomas8251 in forum Forms
    Replies: 3
    Last Post: 11-09-2011, 11:46 AM
  2. CInt and Invalid Use of Null
    By drewetzel in forum Access
    Replies: 4
    Last Post: 10-21-2011, 03:52 PM
  3. DLookUp function giving invalid use of null error
    By shubhamgandhi in forum Programming
    Replies: 4
    Last Post: 07-21-2011, 06:04 PM
  4. Invalid use of Null
    By Wayne311 in forum Programming
    Replies: 4
    Last Post: 01-27-2011, 05:10 PM
  5. Invalid Use of Null!?!
    By Kipster1203 in forum Access
    Replies: 4
    Last Post: 05-13-2010, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums