Results 1 to 3 of 3
  1. #1
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150

    Data Type MisMatch While Checking IsNUll

    Hi



    Code:
    Dim rec As StringDim but As String
    Dim Lid2 As String
    Dim sqlid As String
    Dim rst As Recordset
    Dim cdb As Database
    
    
    Lid2 = Me.Text0 'Job_No
    
    
    sqlid = "SELECT IsNull([Sale_Ended_Date]) FROM Repair WHERE Job_No = " & Lid2
    
    
    If IsNull(Text0) Then
    MsgBox "Job No Cannot Be Empty !!!", vbInformation, "Job No required"
    Me.Text0.SetFocus
    ElseIf (sqlid) Then
    CurrentDb.Execute "Update Repair SET [Sale_Ended_Date] = '" & Format(Now()) & "' WHERE [Job_No]= " & Lid2 & " "
    When i run the above code i get Datatype mismatch error in second IF, Hope you could help me out to sort this problem?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    The only time you can write If (or any variation thereof) followed by a reference only is if the reference evaluates to True or False (or perhaps the equivalents of Yes/No, -1, 0). Your reference is to a variable that is declared as a string.
    Last edited by Micron; 11-07-2019 at 10:42 PM. Reason: spelin and gramur
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    sqlid is a String variable. The SQL statement is just a string of characters. Would have to use the string to open a recordset. Use DLookup instead to return a value from table that can be tested in If condition.

    ElseIf IsNull(DLookup("[Sale_Ended_Date]", "Repair", "Job_No = " & Lid2)) Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Data Type MisMatch
    By Eranka in forum Access
    Replies: 4
    Last Post: 10-31-2019, 03:58 AM
  2. Data type mismatch
    By DMT Dave in forum Access
    Replies: 7
    Last Post: 06-14-2019, 10:00 AM
  3. Data Type Mismatch
    By Mtyetti2 in forum Queries
    Replies: 3
    Last Post: 10-23-2013, 11:48 AM
  4. Data Type Mismatch in SQL
    By Phred in forum Queries
    Replies: 2
    Last Post: 01-04-2012, 03:40 PM
  5. data type mismatch
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 08-02-2010, 04:15 PM

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