Coding Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I have two codes for you guys to look at, the first code works properly and
is an example.

DoCmd.OpenForm "tblPropellant Query", , , "PLANAM = '" &
Me!Plastisizer.Value & "' And PLAPCT between " & Nz(LowPCT.Value, 0) & " and
" & Nz(HighPCT.Value, 0)

This Code is not working and gives me a data type mismatch error, I think it
is my quotes, can someone look at it and see why it is wrong.


DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" & Me!Oxidizer & "' &
" And " & OX1PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX2NAM]= '" & Me!Oxidizer & "' & " And " &
OX2PCT between " & Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "'
OR [OX3NAM]= '" & Me!Oxidizer & "' & " And " & OX3PCT between " &
Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" &
Me!Oxidizer & "' & " And " & OX4PCT between " & Nz(LowPCT.Value, 0) & " and "
& Nz(HighPCT.Value, 0)

I hope the code is not to long for you to see it properly on the message board
I put the above code together from two seperate codes trying to make one
code be able to do both. If you need extra information just ask.

Thanks,
James
 
I've spotted at least one problem - you've got strings (and me) confused

you have
" And " & OX1PCT between " & Nz(LowPCT.Value, 0) & " and " &
this bit should be
" And OX1PCT between " & Nz(LowPCT.Value, 0) & " and " &
 
actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
 
DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


James said:
JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
JackP said:
actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
DoCmd.OpenForm "tblPropellant Query", , ,"[OX1NAM]= '" & Me!Oxidizer & "' And
" & " " OX1PCT between " & Nz(LowPCT.Value, 0) _
^ I get an expected end of statement here.

& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And " & OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And " & OX3PCT between " & Nz(LowPCT.Value,0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And " & OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

I get an end of statement message at the point indicated.

You are right though, there should be a more efficient way of sending code
accross a program like this. It is very difficult to see what is happening.

Thanks for your help,
James

Chaim said:
DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


James said:
JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
JackP said:
actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
James,

There are 3 or 4 errors here.
1. Where you get the 'Expected end of statement'- remove one of the quote
characters.
2. Wherever you have " And " & OX?PCT between- remove the " & characters.
There are 3 of these situations.

I think that catches all of the syntax issues. I wouldn't want to guarantee
that though.

Good Luck!
--
Chaim


James said:
DoCmd.OpenForm "tblPropellant Query", , ,"[OX1NAM]= '" & Me!Oxidizer & "' And
" & " " OX1PCT between " & Nz(LowPCT.Value, 0) _
^ I get an expected end of statement here.

& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And " & OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And " & OX3PCT between " & Nz(LowPCT.Value,0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And " & OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

I get an end of statement message at the point indicated.

You are right though, there should be a more efficient way of sending code
accross a program like this. It is very difficult to see what is happening.

Thanks for your help,
James

Chaim said:
DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


James said:
JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
:

actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
Chaim,

Well at least it started running this time instead of turning the words red :)
Now I have a run-time error: Syntax error for a missing operator here is
the code again with the changes.

DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" & Me!Oxidizer & "'
And OX1PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And OX3PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

Thanks,
James

Chaim said:
James,

There are 3 or 4 errors here.
1. Where you get the 'Expected end of statement'- remove one of the quote
characters.
2. Wherever you have " And " & OX?PCT between- remove the " & characters.
There are 3 of these situations.

I think that catches all of the syntax issues. I wouldn't want to guarantee
that though.

Good Luck!
--
Chaim


James said:
DoCmd.OpenForm "tblPropellant Query", , ,"[OX1NAM]= '" & Me!Oxidizer & "' And
" & " " OX1PCT between " & Nz(LowPCT.Value, 0) _
^ I get an expected end of statement here.

& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And " & OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And " & OX3PCT between " & Nz(LowPCT.Value,0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And " & OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

I get an end of statement message at the point indicated.

You are right though, there should be a more efficient way of sending code
accross a program like this. It is very difficult to see what is happening.

Thanks for your help,
James

Chaim said:
DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


:

JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
:

actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
Chaim,
I found it, I had left one of the ' in the code before the or statement.

Thank You Very Much!!
James

Chaim said:
James,

There are 3 or 4 errors here.
1. Where you get the 'Expected end of statement'- remove one of the quote
characters.
2. Wherever you have " And " & OX?PCT between- remove the " & characters.
There are 3 of these situations.

I think that catches all of the syntax issues. I wouldn't want to guarantee
that though.

Good Luck!
--
Chaim


James said:
DoCmd.OpenForm "tblPropellant Query", , ,"[OX1NAM]= '" & Me!Oxidizer & "' And
" & " " OX1PCT between " & Nz(LowPCT.Value, 0) _
^ I get an expected end of statement here.

& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And " & OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And " & OX3PCT between " & Nz(LowPCT.Value,0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And " & OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

I get an end of statement message at the point indicated.

You are right though, there should be a more efficient way of sending code
accross a program like this. It is very difficult to see what is happening.

Thanks for your help,
James

Chaim said:
DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


:

JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
:

actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
Hi James

In the case of getting complex SQL queries written,
if you have a warchest of pre-written string formatting
code you generate them with better quicker results.

It is a case of having the solution at hand rather than having
to respond to the vagaries of the moment.

At first sight the following probably looks like more work,
but if the sub components are the result of years of reuse
the cut and paste aspect rather than being a case of errors
as in most cases; becomes instead a source of well known tried
tested and bug free assistance.

When you come to creating search forms where there is an
arbitrary number of fields to search with different criteria
including "=" and "LIKE" for text fields it will save your bacon.

Regards - John

Private Sub Load_tblPropellantForm()

Dim strWhereClause As String
Dim strPerCentClause As String
Dim HiPCT As Double
Dim LoPCT As Double

HiPCT = Nz(LowPCT, 0)
LoPCT = Nz(LowPCT, 0)

If HiPCT = LoPCT Then
strPerCentClause = " = " & LoPCT " & vbNewLine
Else
strPerCentClause = "BETWEEN " & LoPCT & " AND " & HoPCT & vbNewLine
End If

strWhereClause = ""
strWhereClause = AppendClause(strWhereClause, "[OX1NAM] = '" & Me!Oxidizer &
"', "AND") ' comment allowed
strWhereClause = AppendClause(strWhereClause, "[OX1PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX2NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX2PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX3NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX3PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX4NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX4PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX5NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX5PCT] = '" &
strPerCentClause, "AND")

'Debug.Print strWhereClause ' Un comment to trouble shoot
DoCmd.OpenForm "tblPropellant Query", , ,strWhereClause

End Sub

' Single demo function
Function AppendClause(Original As String, ExtraClause As String, Separator
As String) As String
If Original & "" = "" Then
AppendClause = ExtraClause

Exit Function
End If

If ExtraClause & "" = "" Then
AppendClause = Original


Exit Function
End If


AppendClause = Original & " " Separator & " " & ExtraClause & " " &
vbNewLine

End Function

James said:
Chaim,
I found it, I had left one of the ' in the code before the or statement.

Thank You Very Much!!
James

Chaim said:
James,

There are 3 or 4 errors here.
1. Where you get the 'Expected end of statement'- remove one of the quote
characters.
2. Wherever you have " And " & OX?PCT between- remove the " & characters.
There are 3 of these situations.

I think that catches all of the syntax issues. I wouldn't want to guarantee
that though.

Good Luck!
--
Chaim


James said:
DoCmd.OpenForm "tblPropellant Query", , ,"[OX1NAM]= '" & Me!Oxidizer & "' And
" & " " OX1PCT between " & Nz(LowPCT.Value, 0) _
^ I get an expected end of statement here.

& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And " & OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And " & OX3PCT between " & Nz(LowPCT.Value,0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And " & OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

I get an end of statement message at the point indicated.

You are right though, there should be a more efficient way of sending code
accross a program like this. It is very difficult to see what is happening.

Thanks for your help,
James

:


DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


:

JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
:

actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
John,

Yeah that is very handy,
As a matter of fact I had never used microsft access before I started this
project a week ago. There was already some basic code in the database and by
copy and pasting that code and making small alterations I had come up with a
fairly good search form. So I agree that having a good library of code
laying around can be a god send. :)

-James

John Griffiths said:
Hi James

In the case of getting complex SQL queries written,
if you have a warchest of pre-written string formatting
code you generate them with better quicker results.

It is a case of having the solution at hand rather than having
to respond to the vagaries of the moment.

At first sight the following probably looks like more work,
but if the sub components are the result of years of reuse
the cut and paste aspect rather than being a case of errors
as in most cases; becomes instead a source of well known tried
tested and bug free assistance.

When you come to creating search forms where there is an
arbitrary number of fields to search with different criteria
including "=" and "LIKE" for text fields it will save your bacon.

Regards - John

Private Sub Load_tblPropellantForm()

Dim strWhereClause As String
Dim strPerCentClause As String
Dim HiPCT As Double
Dim LoPCT As Double

HiPCT = Nz(LowPCT, 0)
LoPCT = Nz(LowPCT, 0)

If HiPCT = LoPCT Then
strPerCentClause = " = " & LoPCT " & vbNewLine
Else
strPerCentClause = "BETWEEN " & LoPCT & " AND " & HoPCT & vbNewLine
End If

strWhereClause = ""
strWhereClause = AppendClause(strWhereClause, "[OX1NAM] = '" & Me!Oxidizer &
"', "AND") ' comment allowed
strWhereClause = AppendClause(strWhereClause, "[OX1PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX2NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX2PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX3NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX3PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX4NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX4PCT] = '" &
strPerCentClause, "AND")

strWhereClause = AppendClause(strWhereClause, "[OX5NAM] = '" & Me!Oxidizer &
"', "AND")
strWhereClause = AppendClause(strWhereClause, "[OX5PCT] = '" &
strPerCentClause, "AND")

'Debug.Print strWhereClause ' Un comment to trouble shoot
DoCmd.OpenForm "tblPropellant Query", , ,strWhereClause

End Sub

' Single demo function
Function AppendClause(Original As String, ExtraClause As String, Separator
As String) As String
If Original & "" = "" Then
AppendClause = ExtraClause

Exit Function
End If

If ExtraClause & "" = "" Then
AppendClause = Original


Exit Function
End If


AppendClause = Original & " " Separator & " " & ExtraClause & " " &
vbNewLine

End Function

James said:
Chaim,
I found it, I had left one of the ' in the code before the or statement.

Thank You Very Much!!
James

Chaim said:
James,

There are 3 or 4 errors here.
1. Where you get the 'Expected end of statement'- remove one of the quote
characters.
2. Wherever you have " And " & OX?PCT between- remove the " & characters.
There are 3 of these situations.

I think that catches all of the syntax issues. I wouldn't want to guarantee
that though.

Good Luck!
--
Chaim


:

DoCmd.OpenForm "tblPropellant Query", , ,"[OX1NAM]= '" & Me!Oxidizer & "' And
" & " " OX1PCT between " & Nz(LowPCT.Value, 0) _
^ I get an expected end of statement here.

& " and " & Nz(HighPCT.Value, 0) & " OR [OX2NAM]= '" & Me!Oxidizer &
"' And " & OX2PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0) & " OR [OX3NAM]= '" & Me!Oxidizer &
"' And " & OX3PCT between " & Nz(LowPCT.Value,0) _
& " and " & Nz(HighPCT.Value, 0) & "' OR [OX4NAM]= '" & Me!Oxidizer
& "' And " & OX4PCT between " & Nz(LowPCT.Value, 0) _
& " and " & Nz(HighPCT.Value, 0)

I get an end of statement message at the point indicated.

You are right though, there should be a more efficient way of sending code
accross a program like this. It is very difficult to see what is happening.

Thanks for your help,
James

:


DoCmd.OpenForm "tblPropellant Query", , ,
"[OX1NAM]= '" & Me!Oxidizer & "' And " & "OX1PCT between " _
^ Add a
quote here
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
& "' OR [OX2NAM]= '" & Me!Oxidizer _
^ why is this here? Should not be.
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
^ why is this here? Should not be.
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

I probably didn't get all of them. This is REAL HARD to read, certainly in
the News reader I'm using. In general, you seem to have extraneous
apostrophes/single quotes (') surrounding all of your OR clauses.

Good Luck! I hope this doesn't look like this for you. No wonder you're
having problems sorting this out.
--
Chaim


:

JackP,

ok I think I removed the quotes you siad to, but now I get a complie error:
Syntax Error. My code looks like this now:
DoCmd.OpenForm "tblPropellant Query", , , "[OX1NAM]= '" &
Me!Oxidizer & "' And " & OX1PCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0) & "' OR
[OX2NAM]= '" & Me!Oxidizer _
& "' And " & OX2PCT between " & Nz(LowPCT.Value, 0) & " and " &
Nz(HighPCT.Value, 0) & "' OR [OX3NAM]= '" _
& Me!Oxidizer & "' And " & OX3PCT between " & Nz(LowPCT.Value,
0) & " and " & Nz(HighPCT.Value, 0) _
& "' OR [OX4NAM]= '" & Me!Oxidizer & "' And " & OX4PCT between "
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)

As for it being a NHS abrieviation... I don't know what NHS means but it is
the actual name of the field, and it is an abrieviation for Oxidizer 1
Percent ect.

-James
:

actually, it looks like you've repeated this every time you've got a line I
mentioned (with OX1PCT, OX2PCT, OX3PCT etc).

Incidentally, is that some sort of NHS abbreviation?
 
Back
Top