Results 1 to 3 of 3
  1. #1
    gazzy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2019
    Posts
    1

    Help with run-time error '91': Objected variable or With block variable not set

    Keep getting "Object variable or With block variable not set" error with this INSERT INTO code. Any help would be appreciated.

    Code:
     
    Private Sub cmdRecordambient_Click()
    
    'add data to table
    CurrentDb.Execute "INSERT INTO AmbientRubberResults(DateTested, SampleName, TotalVol, TotalMass, Mesh8, Mesh10, Mesh12, Mesh14, Mesh16, Mesh20, Mesh30, Mesh40, Mesh50, Mesh60, Mesh70, Mesh100, MeshPan, AppDens, Res8, Res10, Res12, Res14, Res16, Res20, Res30, Res40, Res50, Res60, Res70, Res100, ResPan, PS8, PS10, PS12, PS14, PS16, PS20, PS30, PS40, PS50, PS60, PS70, PS100, PSPan, PassFail) " & _
     " VALUES(" & Me.txtDatetested & ",'" & Me.txtSamplename & "','" & Me.txtTotalvol & "','" & Me.txtTotalmass & "','" & Me.txt8mass & "','" & Me.txt10mass & "','" & Me.txt12mass & "','" & Me.txt14mass & "','" & Me.txt16mass & "','" & Me.txt20mass & "','" & Me.txt30mass & "','" & Me.txt40mass & "','" & Me.txt50mass & "','" & Me.txt60mass & "','" & Me.txt70mass & "','" & Me.txt100mass & "','" & Me.txtPanmass & "','" & Form.Recordset.Fields("txtDens") & "','" & Form.Recordset.Fields("txt8results") & "','" & Me.txt10results & "','" & Me.txt12results & "','" & Me.txt14results & "','" & Me.txt16results & "','" & Me.txt20results & "','" _
    & Me.txt30results & "','" & Me.txt40results & "','" & Me.txt50results & "','" & Me.txt60results & "','" & Me.txt70results & "','" & Me.txt100results & "','" & Me.txtPanresults & "','" & Form.Recordset.Fields("txtPassfail") & "','" & Form.Recordset.Fields("txtPS8") & "','" & Me.txtPS10 & "','" & Me.txtPS12 & "','" & Me.txtPS14 & "','" & Me.txtPS16 & "','" & Me.txtPS20 & "','" & Me.txtPS30 & "','" & Me.txtPS40 & "','" & Me.txtPS50 & "','" & Me.txtPS60 & "','" & Me.txtPS70 & "','" & Me.txtPS100 & "','" & Me.txtPSPan & "')"
    
    End Sub


  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    suggest adopt the recommended practice and create a string variable, assign your sql code to that,m then execute it. You can also debug.print the string, and copy paste it from the immediate window into a new query which can also help you see if you have missed anything

    Code:
    dim sqlStr as string
    sqlStr="SELECT......"
    debug.print sqlStr
    currentdb.execute sqlStr
    also ensure the top of each module has Option Explicit just below the other Option line

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Agree with the advice but I suspect the procedure doesn't know what this is
    Form.Recordset.Fields
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Error 91 Object Variable or Block Variable Not Set
    By mindbender in forum Programming
    Replies: 5
    Last Post: 05-01-2017, 12:01 PM
  2. Replies: 6
    Last Post: 02-11-2016, 02:05 PM
  3. Object variable or With block variable not defined
    By PorscheMan in forum Programming
    Replies: 3
    Last Post: 01-16-2013, 01:53 PM
  4. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  5. Replies: 4
    Last Post: 08-05-2010, 01:26 PM

Tags for this Thread

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