Results 1 to 4 of 4
  1. #1
    PorscheMan is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    4

    Object variable or With block variable not defined


    I have a form with a multi select list box set to Extended. On a command button, I have the following code. I am getting an error message stating Object variable or With block variable not set. What am I missing in the code below? Any help appreciated. Thanks

    Code:
    Private Sub Search_Click()
    On Error GoTo Err_Search_Click
        Dim varItem As Variant
        Dim strWhere As String
        Dim strWhere1 As String
        Dim lngLen As Long
        Dim strDelim As String
        Dim db As DAO.Database
        Dim qdf As DAO.QueryDef
        Dim strSQL As String
        Dim strSQL1 As String
        With Me.lstMfg
        For Each varItem In .ItemsSelected
          If Not IsNull(varItem) Then
            strWhere1 = strWhere1 & "'" & strDelim & .ItemData(varItem) & strDelim & "',"
        End If
        Next varItem
      End With
    lngLen = Len(strWhere1) - 1
      If lngLen > 0 Then
        strWhere1 = "[Make] IN (" & Left$(strWhere1, lngLen) & ") "
        End If
        
        strWhere = strWhere1
    If Len(strWhere) > 0 And Len(strWhere1) > 0 Then
      strWhere = strWhere & " AND " & strWhere1
    Else
      strWhere = strWhere & strWhere1
    End If
    
    Set db = CurrentDb
    '*** create the query based on the information on the form
    strSQL = "SELECT qryByMake.* FROM qryByMake "
    strSQL = strSQL & " WHERE " & strWhere
    Set qdf = db.QueryDefs("qryByMake1")
        qdf.SQL = strSQL
    '*** open the query
    strSQL1 = "SELECT qryByMake1.BaseVehicle, qryByMake1.BaseVehicleID, qryByMake1.PartID, qryByMake1.PartsDescription, qryByMake1.PartNumber, qryByMake1.Percar_Quantity, qryByMake1.Remarks1, qryByMake1.Remarks2, qryByMake1.Remarks3, qryByMake1.Class, qryByMake1.Line INTO [Missing Parts] " & vbCrLf & _
    "FROM qryByMake1 LEFT JOIN PartApplications ON (qryByMake1.PartID = PartApplications.PartID) AND (qryByMake1.BaseVehicleID = PartApplications.BaseID) " & vbCrLf & _
    "WHERE (((PartApplications.PartID) Is Null));"
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL1
    DoCmd.OpenTable "Missing Parts", acViewNormal, acEdit
    DoCmd.SetWarnings True
    Exit_Search_Click:
        Exit Sub
    Err_Search_Click:
        If Err.Number = 3265 Then   '*** if the error is the query is missing
            Resume Next             '*** then skip the delete line and resume on the next line
        Else
            MsgBox Err.Description      '*** write out the error and exit the sub
            Resume Exit_Search_Click
        End If
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Which line is triggering the error? Comment out the On Error GoTo line so the debugger will hit the error line.
    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.

  3. #3
    Missinglinq's Avatar
    Missinglinq is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You have the strDelim Variable Dimmed as a String, and you're using it in your code, but you haven't assigned a Value to it!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That means strDelim is just empty. Don't think would trigger that error.

    Since the apostrophe delimiter is hard coded, strDelim is not needed.
    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. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. Object variable or With block variable not set
    By walter189 in forum Programming
    Replies: 1
    Last Post: 07-28-2011, 08:51 AM
  4. DSum criteria using a variable that has been defined
    By beanhead0321 in forum Programming
    Replies: 5
    Last Post: 07-24-2011, 09:57 PM
  5. Replies: 4
    Last Post: 08-05-2010, 01:26 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