Thanks!
Okay i gave that solution a go. Gives me a new error now.
Compile Error: User-defined type not defined. Highlights this line as the problem.
Public Sub HaweraSales(objForm As Form)
Any ideas?
Main Topics
Browse All TopicsHi all :)
Just a quick VBA/Excel Question. I'm fairly new to VBA.
I'm currently trying to query an informix database, where as the user would put the specific date range they require in two textboxes, i,e '1/5/2007' '31/5/2007'. Then they would hit the refresh button and the query would use the values they just entered.
My main problem so far is getting the correct syntax for the SQL query to use the values in the textboxes. The particular piece of code in question follows.
Public Sub HaweraSales()
Dim obj As Object
Dim rec As ADODB.Recordset
Set obj = CreateObject("ADODB.Connec
obj.Open "dsn=p615;"
obj.BeginTrans
obj.Execute ("select spddate, sphprodno, sum(spdvalue) sales, sum(spdgrossprofit) profit from salesbyperiod where sphwhseno = " & Chr(34) & "HWF" & Chr(34) & " and sphdepartment = " & Chr(34) & "50" & Chr(34) & " and spddate >=" & Chr(34) & Me.txtDate & Chr(34) & " and spddate <='" & Chr(34) & Me.txtDate1 & Chr(34) & " group by 1,2 into temp a1 with no log")
obj.CommitTrans
Me.txtDate and Me.txtDate1 being the text boxes in question. It gives me an error saying - Compile Error - Invalid use of Me Keyword. I understand that Me cant be used in modules?
Any possible alternative syntax that does the same thing? I hope this makes sense.
Thanks in advance for any possible help anyone can give.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Alright, i think i found a solution to my above issue. As in setting a reference to "Microsoft ActiveX Data Objects 2.7.
As seen here: http://p2p.wrox.com/topic.
Except when i go to select that particular reference it tells me : Name Conflicts with Existing Module, Project, or Object Library.
I then renamed the project via Tools -> VBAProject Properties to something different. Then went to reselect the Microsoft ActiveX Data Objects 2.7, and it still gives me the same Name conflict error. Any ideas?
Thanks for the help
I have solved the naming conflict error. Still giving me a User Type not defined Error however. Even after i have set the reference.
The break is once again on this line.
Public Sub HaweraSales(objForm As Form)
I'll paste all my code below:
Public Sub HaweraSales(objForm As Form)
Dim obj As Object
Dim rec As ADODB.Recordset
Set obj = CreateObject("ADODB.Connec
obj.Open "dsn=p615;"
obj.BeginTrans
obj.Execute ("select spddate, sphprodno, sum(spdvalue) sales, sum(spdgrossprofit) profit from salesbyperiod where sphwhseno = " & Chr(34) & "HWF" & Chr(34) & " and sphdepartment = " & Chr(34) & "50" & Chr(34) & " and spddate >=" & Chr(34) & objForm.txtDate & Chr(34) & " and spddate <='" & Chr(34) & objForm.txtDate1 & Chr(34) & " group by 1,2 into temp a1 with no log")
obj.Execute ("select (spddate) fdate, sum(sales) fsales, sum(profit) fprofit from a1 group by 1 into temp a2 with no log")
obj.Execute ("select spddate, sphprodno, sum(spdvalue) sales, sum(spdgrossprofit) profit from salesbyperiod where sphwhseno = " & Chr(34) & "HWF" & Chr(34) & " and sphdepartment != " & Chr(34) & "50" & Chr(34) & " and spddate >='" & objForm.txtDate & Chr(34) & " and spddate <='" & objForm.txtDate1 & Chr(34) & " group by 1,2 into temp b1 with no log")
obj.Execute ("select (spddate) mdate, sum(sales) msales, sum(profit) mprofit from b1 group by 1 into temp b2 with no log")
obj.Execute ("select ohorddmy, count(ohintref) invcount from ohhist where ohwhse = " & Chr(34) & "HWF" & Chr(34) & " and ohorddmy >='" & objForm.txtDate & Chr(34) & " and ohorddmy <='" & objForm.txtDate1 & Chr(34) & " group by 1 into temp c1 with no log")
obj.CommitTrans
Set rec = New ADODB.Recordset
rec.ActiveConnection = obj
rec.Source = "select unique spddate, fsales, fprofit, msales, mprofit, invcount from salesbyperiod, outer a2, outer b2, outer c1 where spddate = fdate and spddate = mdate and spddate = ohorddmy and spddate >= " & Chr(34) & objForm.txtDate & Chr(34) & " and spddate <= " & Chr(34) & objForm.txtDate1 & Chr(34) & " order by 1"
rec.CursorType = 0
rec.CursorLocation = 2
rec.LockType = 1
rec.Open
'Get the worksheet
Workbooks("Hawera Daily Sales Comparison May 07.xls").Worksheets("sheet
'Fill in the headers
For Count = 1 To rec.Fields.Count
Workbooks("Hawera Daily Sales Comparison May 07.xls").Worksheets("sheet
Next
Dim current_row
current_row = 3
rec.MoveFirst
Do
For Count = 1 To rec.Fields.Count
Workbooks("Hawera Daily Sales Comparison May 07.xls").Worksheets("sheet
Next
rec.MoveNext
current_row = current_row + 1
Loop While Not rec.EOF
Sheets("sheet1").Select
End Sub
Business Accounts
Answer for Membership
by: pkwanPosted on 2007-05-07 at 23:38:42ID: 19047937
You are right that "Me cannot be used in modules". To solve this problem, try to supply the form as a parameter to the method, as in the following reference: asp?TOPIC_ ID=10386
http://p2p.wrox.com/topic.