Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts

    Invalid Use of Null error message

    Friends, what is wrong with this statement:

    Private Sub Comando0_Click()

    Dim get_Company As String
    Dim identify_company As String

    Dim Db As Database, rs As Recordset, sql As String, rs2 As Recordset, rs3 As Recordset

    Set Db = CurrentDb
    Set rs = Db.OpenRecordset("SELECT Name_Of_Company FROM Tbl_Test")

    rs.MoveFirst
    get_Company = rs.Fields(0)
    identify_company = DLookup("Id_Company", "Tbl_Company", "Company = 'get_Company'")


    End Sub

    "get_company" has a value. In the table "Tbl_Company" in the field "Company"
    has a value equal to the value "get_company".

    I get an error message: Invalid Use of Null.


    Thanks for helping.

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    There is no company named get_Company. You want to use the variable's value, not the variables name:

    Code:
    identify_company = DLookup("Id_Company", "Tbl_Company", "Company = '" & get_Company & "'")
    
    Be very careful with the single and double quotes. I have tried to make it clear.

  3. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-09-07)

  4. #3
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    Rui, worked exactly as I am trying. Thank you for helping me again.

  5. #4
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Sorry, Fabio, I don't quite understand if it worked or not. Shall I understand that it worked?

  6. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-09-07)

  7. #5
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    Yes, it worked. Prior did not return any value (despite not having any error message in the syntax) but now returns the value.

    Thank you.

  8. #6
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    I am glad it's working .

    There was no syntax error message, because there was no syntax error. You were simply searching for a company with a name of "get_Company" and obviously there was none.

  9. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-09-08)

  10. #7
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    Now I understand. Thanks for the additional explanation.

  11. #8
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    You're welcome.

  12. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-09-08)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •