How to find a value in excel spreadsheet then add to a access query

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Try to find a value in the column in excel (In this case, "Rear Door - NS - See Drawing") then use it in the access database query??
The error says "Command text was not set for the command object"

VBA Code:
Private Sub SetIDLengthofRearDoorPoleHandelPostion()

   

    Dim iRow As Integer
    Dim qry As String
    Dim rs As Object: Set rs = OpenConAndGetRS(qry)

   
   

  With ThisWorkbook.Worksheets("Job Card Master")
  
  Select Case Me.Body_Type.Value
    Case ("Tippa with STD Cage")
    qry = "SELECT * FROM [IDAndData] " & _
    " WHERE [Vehicle]='" & Model_Type.Text & "'" & _
    " AND [FramesWidth&Height]='" & Gantry_Height_Width.Text & "'" & _
    " AND [Material/Part]='" & .Range("E1:F" & .UsedRange.Rows.Count).Find("Rear Door - NS - See Drawing", LookIn:=xlValues, lookat:=xlWhole).Value
    End Select
   
    iRow = .Range("E1:F" & .UsedRange.Rows.Count).Find("TC - TL - THTT", LookIn:=xlValues, lookat:=xlWhole).Row
      If Not (rs.BOF Or rs.EOF) Then
            Do While Not rs.EOF
                .Cells(iRow, 5) = rs.Fields("LengthofRearDoorPole&HandelPostion").Value
                iRow = iRow + 1
                rs.MoveNext
            Loop
        End If
        rs.Close: Set rs = Nothing
    End With

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If using qry prior to qry being constructed isn't the problem,
maybe try a variable = the range.find part and just use the variable in construction of the qry string.
(my 2010 doesn't accept what you have as a range for the .find)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top