Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Statement Problem in form

Status
Not open for further replies.

mdmarney

IS-IT--Management
Jan 16, 2003
68
US
Private Sub Form_Current()

Set rs = CurrentDb.OpenRecordset("Select * from tbl_Attendants where Parish or Group ID = " & me!Parish or Group ID & ")

rs.MoveLast

Me.tx_Count_Box_2 = rs.RecordCount

End Sub *************
M. MARNEY
 
Boy, I'm in too much of a hurry...

The code posed above will not work. Any suggestions? *************
M. MARNEY
 
After a brief second, I realized you have a field called "Parish or Group ID", right?

Try embedding QUOTES around it in the criteria:

Parish or Group ID = [red]'[/red]" & me!Parish or Group ID & "[red]'[/red]")

Your bigger problem might be the use of the keyword OR in your field name, not to mention the spaces. You'll probably end up needing:

[Parish or Group ID] = [red]'[/red]" & me![Parish or Group ID] & "[red]'[/red]")

As a rule of thumb, don't use embedded spaces in field names, and try to stay away from reserved or key words in Access, such as NAME, DATE, OR, AND, etc etc etc...

Jim

Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Thanks for the tip. I changed to the following after editing the field names.
Set rs = CurrentDb.OpenRecordset("Select * from tbl_Attendants where [Parish_Group_ID] = '" & Me![Parish_Group_ID] & "'")

This did not work. Any thoughts *************
M. MARNEY
 
First, DO YOU KNOW that there should be a match or two?

Second of all, the syntax LOOKS correct, assuming you have textual data in your field.

Do you need a semi at the end? I don't often use raw SQL for record sets, but I think that you need a semi to end a sql clause when used like this... ??

where [Parish_Group_ID] = '" & Me![Parish_Group_ID] & "' [red] ; [/red] ")

to the final result resolves to something like:

[Parish_Group_Id] = 'FOO';




Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Hmmm....
There are matches.
I was using this code from another person posting, but something you said made me wonder...
These are both long int fields.
Is that the problem?
*************
M. MARNEY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top