create query def compile error data member not found

Well ive only been working on this all day so not too long then!!

can anyone tell me how i can get the createquerydef member to be recognised i have ticked just about every refrence in teh vba tools refreneces and still no joy so if anyone can point me in the right direction that would be great.

code is below
Function CreateSPT(SPTQueryName As String, SQLString As String, ConnectString As String)
      '-----------------------------------------------
      ' FUNCTION: CreateSPT()
      ' PURPOSE:
      '   Creates an SQL pass-through query using the supplied arguments:
      '      SPTQueryName: the name of the query to create
      '      SQLString: the query's SQL string
      '      ConnectString: the ODBC connect string, this must be at
      '         least "ODBC;"
      '-----------------------------------------------
         Dim mydatabase As Database, myquerydef As QueryDef
 
         Set mydatabase = DBEngine.Workspaces(0).Databases(0)
         Set myquerydef = mydatabase.CreateQueryDef(SPTQueryName)
 
         myquerydef.Connect = ConnectString
         myquerydef.sql = SQLString
         myquerydef.Close
      End Function
 
  Sub test()
 
                
   CreateSPT("delivery_details", "select patient_name, ship_to, Unit, Treatment, delivery_date, datename(day,delivery_date) as day, special_reason, Delivery_not_required, Quantity_required From TBL_Delivery_details Where (Delivery_date between ([forms!FRM_input for passthrough!combo3!]) And ([forms!FRM_input for passthrough!combo5]))And Delivery_not_required = 0", "odbc;dsn=factor;database=factortest;usid=sa;pwd=arsenal1") = jd1
 
 
  End Sub

Open in new window

LVL 25
slam69Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
try
changing this

Dim mydatabase As Database, myquerydef As QueryDef


to

Dim mydatabase As Dao.Database, myquerydef As Dao.QueryDef


and make sure you have DAO in your references
0
Rey Obrero (Capricorn1)Commented:
don't forget to  do a Debug>compile
0
Rey Obrero (Capricorn1)Commented:
?? not sure about the connect line that you have
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

slam69Author Commented:
Hi,

ok that work but i still cant get it to pick up the combo box variable it is saying its an external reference, please see my amended connection line. i have taken out the odbc settings as these are working fine
CreateSPT("delivery_details", "select patient_name, ship_to, Unit, Treatment, delivery_date, datename(day,delivery_date) as day, special_reason, Delivery_not_required, Quantity_required From TBL_Delivery_details Where (Delivery_date between " & [forms!FRM_input for passthrough!combo3!] & "And " & [forms!FRM_input for passthrough!combo5] & ")And Delivery_not_required = 0", "odbc;") 

Open in new window

0
Rey Obrero (Capricorn1)Commented:

is this the actual name of the form --> FRM_input for passthrough ?

CreateSPT("delivery_details", "select patient_name, ship_to, Unit, Treatment, delivery_date, datename(day,delivery_date) as day, special_reason, Delivery_not_required, Quantity_required From TBL_Delivery_details Where (Delivery_date between " & [forms]![FRM_input for passthrough]![combo3!] & " And  " & [forms]![FRM_input for passthrough]![combo5] & ") And Delivery_not_required = 0", "odbc;")

or

wrap the date with #


CreateSPT("delivery_details", "select patient_name, ship_to, Unit, Treatment, delivery_date, datename(day,delivery_date) as day, special_reason, Delivery_not_required, Quantity_required From TBL_Delivery_details Where (Delivery_date between #" & [forms]![FRM_input for passthrough]![combo3!] & "# And  #" & [forms]![FRM_input for passthrough]![combo5] & "#) And Delivery_not_required = 0", "odbc;")

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slam69Author Commented:
Well i got it to work really confused why though. i dropped the Parenthesis from around the create spt variable string as it kept giveing me an expected end of statement  error so thought id give it a go. Did that and it kicked into life which im really confused by. just going to rewrite it now to drop the query after it has been displayed so that it can be used as a reusable variable function. thanks for pointing me in the right direction with teh orgiinal question though!! you might hear more from me ;oS

Date_from = Forms!FRM_input!Combo3
  Date_to = Forms!FRM_input!Combo5
   
CreateSPT "delivery_details", "select patient_name, ship_to, Unit, Treatment, delivery_date, datename(day,delivery_date) as day, special_reason, Delivery_not_required, Quantity_required From TBL_Delivery_details Where (Delivery_date between '" & Date_from & " 00:00:00.000' And '" & Date_to & " 00:00:00.000') And Delivery_not_required = 0", "odbc;"
.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.