I think what I need is really simple but I'm new to VBA and am lost at this point .
I want to be able to input a Name into a cell (or input box??), click "GO", and it will query Quickbooks to pull all the transactions for only that name. I've tried Range.Copy but it doesn't copy to the MS query. Here's the pertinent coding - "B4" is where I currently have the name, and "Linda Jones" is where that variable needs to go (both in red below). Thanks for any and all answers!
Sub Macro1()
'
' Macro1 Macro
'
'
Range("B4").Copy
With ActiveWorkbook.Connections("Contacts Fake Company").ODBCConnection
.BackgroundQuery = True
.CommandText = Array( _
"SELECT v_lst_names.name_type, v_lst_names.name, v_lst_contacts.telephone_num1, v_lst_contacts.email, v_txn_sales_re" _
, _
"ceipt_hdr.transaction_date_h, v_txn_sales_receipt_line.unit_price_amt, v_txn_sales_receipt_line.amount_amt, v_txn_s" _
, _
"ales_receipt_line.memo, v_txn_sales_receipt_line.quantity_qnty" & Chr(13) & "" & Chr(10) & "FROM QBReportAdminGroup.v_lst_contacts v_lst_contac" _
, _
"ts, QBReportAdminGroup.v_lst_names v_lst_names, QBReportAdminGroup.v_txn_sales_receipt_hdr v_txn_sales_receipt_hdr," _
, _
" QBReportAdminGroup.v_txn_sales_receipt_line v_txn_sales_receipt_line" & Chr(13) & "" & Chr(10) & "WHERE v_lst_names.id = v_lst_contacts.name_i" _
, _
"d AND v_txn_sales_receipt_hdr.customer_id_h = v_lst_names.id AND v_txn_sales_receipt_line.doc_num_h = v_txn_sales_r" _
, _
"eceipt_hdr.doc_num_h AND ((v_lst_names.name_type='Customer') AND (v_lst_names.name='Linda Jones'))" & Chr(13) & "" & Chr(10) & "ORDER BY v_lst" _
, "_names.name, v_txn_sales_receipt_hdr.transaction_date_h DESC")
Bookmarks