|
-
Aug 18th, 2000, 07:58 AM
#1
Thread Starter
Member
I have the following SQL and I am getting Missing Parameter when I am using it can anyone help me with the syntax
Data1.RecordSource = "Select House.HStreet, OInspect.HourBegin, OInspect.HourEnd From House,OInspect Where House.AgentID = " & Agent(cboAgent.ListIndex) & "And OInspect.ODate > " & txtStart.Text & "And OInspect.ODate < " & txtFinish.Text & " Order By OInspect.ODate"
It uses three variables off aform and fields from two tables
-
Aug 18th, 2000, 10:20 AM
#2
Try this:
"Select House.HStreet, OInspect.HourBegin, OInspect.HourEnd From House,OInspect Where House.AgentID = '" & Agent(cboAgent.ListIndex) & "' And OInspect.ODate > '" & txtStart.Text & "' And OInspect.ODate < '" & txtFinish.Text & "' Order By OInspect.ODate"
I guess another problem was that there was no space before the "And"s..
-
Aug 18th, 2000, 12:14 PM
#3
Frenzied Member
It doesn't make much difference on this query (because it's relatively small) but you should get in the habit of using aliases.
Your query:
"Select House.HStreet, OInspect.HourBegin, OInspect.HourEnd From House,OInspect Where House.AgentID = '" & Agent(cboAgent.ListIndex) & "' And OInspect.ODate > '" & txtStart.Text & "' And OInspect.ODate < '" & txtFinish.Text & "' Order By OInspect.ODate"
could be reworked to:
"Select a.HStreet, b.HourBegin, b.HourEnd From House a, OInspect b Where a.AgentID = '" & Agent(cboAgent.ListIndex) & "' And b.ODate > '" & txtStart.Text & "' And b.ODate < '" & txtFinish.Text & "' Order By b.ODate"
Easier to read and it's shorter (you may run into instances later with large queries where you cannot fit it into a string variable if you don't use aliases).
-
Aug 18th, 2000, 11:50 PM
#4
Thread Starter
Member
Your right I should I was also wondering whether I could use the Between clause to check for a valid date???
-
Aug 19th, 2000, 12:14 AM
#5
The "missing parameter" error is due to misspelling a field name from a table involved in your query (i.e., it is interpreting the misspelled field as a parameter variable for which you have not specified a value). Check your field names in the tables and make sure they match up to the names used in your query.
Also, if you are using Access SQL, your should specify the aliases for your table names with the AS clause and enclose the date values in pound (#) signs. And yes, you can use the BETWEEN clause for the dates. For example, you can modify JHausmann's query as follows:
Code:
"Select a.HStreet, b.HourBegin, b.HourEnd From House AS a, OInspect AS b Where a.AgentID = '" & Agent(cboAgent.ListIndex) & "' And b.ODate BETWEEN #" & txtStart.Text & "# And #" & txtFinish.Text & "# Order By b.ODate"
The above assumes the user has entered valid dates in txtStart and txtFinish, in mm/dd/yy or mm/dd/yyyy format.
"It's cold gin time again ..."
Check out my website here.
-
Aug 19th, 2000, 04:47 AM
#6
Thread Starter
Member
OK so I have put in every version of this SQL and I am still getting missing parameter, I have checked all field names, tried substituting variables and compared it to other SQL's I have written, and though it seems the same something is still wrong
Has anyone got any other suggestions
At the moment the SQL looks like this:"Select a.HStreet, b.HourBegin, b.HourEnd From House AS a, OInspect AS b Where a.AgentID = '" & Agent(cboAgent.ListIndex) & "' And b.ODate BETWEEN #" & txtStart.Text & "# And #" & txtFinish.Text & "# Order By b.ODate"
Just a side note I went into the VisData tool to see if I could find out what was going wrong and entered the following SQL (a variation on the one above using variable names)
Select House.HStreet, OInspect.ODate,OInspect.AgentID From House, OInspect Where (OInspect.ODate Between Start And Finish ) And (OInspect.AgentID =AgentNo) And (House.HouseID = OInspect.HouseID) Order By OInspect.ODate
This works in Visdata so how do I transfer it to the form??????
[Edited by whittam on 08-19-2000 at 07:15 AM]
-
Aug 21st, 2000, 03:24 PM
#7
Frenzied Member
set your SQL statement to a variable, then place a breakpoint on that line that sets the variable's value.
for example
dim sSQL as string
sSQL="Select a.HStreet, b.HourBegin, b.HourEnd From House AS a, OInspect AS b Where a.AgentID = '" & Agent(cboAgent.ListIndex) & "' And b.ODate BETWEEN #" & txtStart.Text & "# And #" & txtFinish.Text & "# Order By b.ODate"
run your program.
when it gets to the break point, press f8 (single step).
in the "immediate window" type ?sSQL
hit return and post the results back here
-
Aug 21st, 2000, 05:00 PM
#8
Thread Starter
Member
sSQL shows the following information at the breakpoint :Select a.HStreet, b.HourBegin, b.HourEnd From House AS a, OInspect AS b Where a.AgentID = '2' And b.ODate BETWEEN #8/15/00# And #8/31/00# Order By b.ODate
The error message is still Runtime error 3061 Too few parameters, expected 1
-
Aug 21st, 2000, 06:03 PM
#9
Frenzied Member
Can you now post the fields in House and Oinspect and what their datatypes are?
-
Aug 21st, 2000, 08:59 PM
#10
Thread Starter
Member
-
Aug 22nd, 2000, 12:57 AM
#11
Lively Member
AgentID, HouseID ?
The House table is missing the AgentID field that you are qualifying on. Is the error in the SQL or table defenition ?
Should you not join the both tables with H.HouseId = OI.HouseID ?
Use better alias than a and b. I always have same alias for same table and defines them as I define the table.
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Aug 22nd, 2000, 06:31 AM
#12
Thread Starter
Member
I did have the join in the SQL at one stage and have now replaced it but am still getting the same error message
the present format is as follows:
Select a.HStreet, b.HourBegin, b.HourEnd From House AS a, OInspect AS b Where b.HouseID = a.HouseID and a.AgentID = '2' And b.ODate BETWEEN #8/15/00# And #8/31/00# Order By b.ODate
I guess using more explicit names for the tables would be better but I still normally but the full table name in to help me understand
-
Aug 22nd, 2000, 07:53 AM
#13
Lively Member
Did you miss this , I think that is your problem.
The House table is missing the AgentID field that you are qualifying on. Is the error in the SQL or table defenition ?
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Aug 22nd, 2000, 11:53 AM
#14
Frenzied Member
Because AgentID is a number, try:
sSQL="Select a.HStreet, b.HourBegin, b.HourEnd From House AS a, OInspect AS b Where b.AgentID = " & Agent(cboAgent.ListIndex) & " And b.ODate BETWEEN #" & txtStart.Text & "# And #" & txtFinish.Text & "# Order By b.ODate" and a.houseID=b.houseID
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|