472,328 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

MS Access front end to SQL Server problem passing Form value to Report

I just changed my Access 2002 database to a SQL Server ADP project. I
had a form where the user entered a value into a text box and when a
command button on the form was clicked a Report was opened. The reports
record source is a query. The query uses the value from the form text
box to restrict the query.
Table name = EggsTable
one of the columns in the table is named: EggColor
Form name = EggColorForm
Form text box name = ColorTextBox

This sql worked for the query before I converted to SQL:

SELECT EggsTable.EggColor
FROM EggsTable
WHERE (((EggsTable.EggColor)=[Forms]![EggColorForm]![ColorTextBox]));

This no longer works. Can I change the syntax somehow to get this to
work? I tried dropping the brackets around the word "Forms", I tried
dropping all the square brackets, etc., nothing worked.

I also tried just opening the report with the report's Server Filter
property set to:
EggColor=N'Forms.EggColorForm.ColorTextBox'

I tried using the Report's open event to pass the form value directly
to the report. I tried setting a variable from the text box value on
the form. So far, nothing works. Any ideas?

Jul 23 '05 #1
7 6276

<ri********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I just changed my Access 2002 database to a SQL Server ADP project. I
had a form where the user entered a value into a text box and when a
command button on the form was clicked a Report was opened. The reports
record source is a query. The query uses the value from the form text
box to restrict the query.
Table name = EggsTable
one of the columns in the table is named: EggColor
Form name = EggColorForm
Form text box name = ColorTextBox

This sql worked for the query before I converted to SQL:

SELECT EggsTable.EggColor
FROM EggsTable
WHERE (((EggsTable.EggColor)=[Forms]![EggColorForm]![ColorTextBox]));

This no longer works. Can I change the syntax somehow to get this to
work? I tried dropping the brackets around the word "Forms", I tried
dropping all the square brackets, etc., nothing worked.

I also tried just opening the report with the report's Server Filter
property set to:
EggColor=N'Forms.EggColorForm.ColorTextBox'

I tried using the Report's open event to pass the form value directly
to the report. I tried setting a variable from the text box value on
the form. So far, nothing works. Any ideas?


I know nothing about ADP, but since MSSQL is a server, it has no concept of
forms or front end interfaces - you need to get the value in your ADP form,
then pass it to MSSQL, preferably as the parameter to a stored proc:

create proc dbo.GetEggColor
@color varchar(10)
as
set nocount on
begin
select EggColor
from dbo.EggsTable
where EggColor = @color
end

You could then use the ADO Connection object or whatever to execute the
stored proc, and present the result set in your report (as far as I can see,
the query you have will return the parameter you pass to it, so it appears
not to do much, but I assume this is just a trivial example). This link has
some examples of calling procs from ASP using ADO, but I guess the concept
is similar from Access:

http://www.aspfaq.com/show.asp?id=2201

If this isn't helpful, you'll probably get more detailed feedback in an
Access or ADP forum on exactly how to pass your value from the front end to
MSSQL.

Simon
Jul 23 '05 #2
Thanks, I tried using a variable but I kept getting the error message,
"You need to declare the variable", I checked and checked and the
variable was declared, BUT, I was just studying SQL syntax and I found
that with SQL you declare a variable with: DECLARE @myVariable as
varchar
what a concept!
I was using the MS Access way to declare a variable which is: Dim as
in
Dim myVariable as string

Also, a couple of other ideas, that I think will work but I haven't
tested yet.

Build RecordSource for the report on the fly:

Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = "SELECT EggColor FROM dbo.EggsTable " & _
"WHERE EggColor='" & Forms!EggColorForm!ColorTextBox & "'"
End Sub

or

rewrite the query as a stored procedure and assign it to the report in
its Prop Sheet
(along with Input Parameters: @EggColor varchar(10) =
Forms![EggColorForm]![ColorTextBox])

create procedure mp_EggColors @EggColor varchar(10)
as
SELECT EggsTable.EggColor
FROM dbo.EggsTable
WHERE (((EggsTable.EggColor)=@EggColor))

Thanks for your help.

Simon Hayes wrote:
<ri********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was opened. The reports record source is a query. The query uses the value from the form text box to restrict the query.
Table name = EggsTable
one of the columns in the table is named: EggColor
Form name = EggColorForm
Form text box name = ColorTextBox

This sql worked for the query before I converted to SQL:

SELECT EggsTable.EggColor
FROM EggsTable
WHERE (((EggsTable.EggColor)=[Forms]![EggColorForm]![ColorTextBox]));
This no longer works. Can I change the syntax somehow to get this to work? I tried dropping the brackets around the word "Forms", I tried dropping all the square brackets, etc., nothing worked.

I also tried just opening the report with the report's Server Filter property set to:
EggColor=N'Forms.EggColorForm.ColorTextBox'

I tried using the Report's open event to pass the form value directly to the report. I tried setting a variable from the text box value on the form. So far, nothing works. Any ideas?

I know nothing about ADP, but since MSSQL is a server, it has no

concept of forms or front end interfaces - you need to get the value in your ADP form, then pass it to MSSQL, preferably as the parameter to a stored proc:

create proc dbo.GetEggColor
@color varchar(10)
as
set nocount on
begin
select EggColor
from dbo.EggsTable
where EggColor = @color
end

You could then use the ADO Connection object or whatever to execute the stored proc, and present the result set in your report (as far as I can see, the query you have will return the parameter you pass to it, so it appears not to do much, but I assume this is just a trivial example). This link has some examples of calling procs from ASP using ADO, but I guess the concept is similar from Access:

http://www.aspfaq.com/show.asp?id=2201

If this isn't helpful, you'll probably get more detailed feedback in an Access or ADP forum on exactly how to pass your value from the front end to MSSQL.

Simon


Jul 23 '05 #3
(rc*********@yahoo.com) writes:
Thanks, I tried using a variable but I kept getting the error message,
"You need to declare the variable", I checked and checked and the
variable was declared, BUT, I was just studying SQL syntax and I found
that with SQL you declare a variable with: DECLARE @myVariable as
varchar
what a concept!


Beware that

DECLARE @myVariable AS varchar

makes @myVariable a varchar(1)! All strings have a maximum length in
SQL Server.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
<ri********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I just changed my Access 2002 database to a SQL Server ADP project. <<>> I tried using the Report's open event to pass the form value directly
to the report. I tried setting a variable from the text box value on
the form. So far, nothing works. Any ideas?


Yes.
Avoid using ADP.
Do you really need to convert your project?

There are some rather odd behaviours in access ADP can be a right pain to
work with.
EG A technique that works fine in one form will not work in another for no
appararent reason.
I think relatively few people are using ADP for serious development.

Fire up google and take a look at posts on the access newsgroup.

--
Regards,
Andy O'Neill
Jul 23 '05 #5
ADP as opposed to what? I mean, what GUI front end for the SQL Server
database?

Also, I have SQL Server 2000 evaluation version on DesktopA and the
same SQL Server version running on DesktopB. I would like to use the
SQL Server Enterprise Manager wizard to copy the database from DesktopA
to DesktopB. SQL Server is running on both PCs as a local system
account (I think, how do I check?). When I start the wizard, it says
(local) for the source server and "use windows authentication", the
next step asks for the destination server and lists (local) and
DESKTOPB, when I pick DESKTOPB and either Windows and SQL
authentication I get the error message, "Cannot connect to the server
DESKTOPB. Please check the server name and try again." I am new to this
so any ideas of what I should try would be appreciated. I don't know if
I need to "register" the servers or anything else I might be leaving
out.

Jul 23 '05 #6
Oh, you mean keep the database as an Access MDB. If that's what you
mean, I know what you mean, I like and prefer Access and I think it can
handle quite a lot but in this case I don't have a choice, everything
else is in SQL and it seems to be best to keep all the databases
consistent.

ADP as opposed to what? I mean, what GUI front end for the SQL Server database?

Also, I have SQL Server 2000 evaluation version on DesktopA and the
same SQL Server version running on DesktopB. I would like to use the
SQL Server Enterprise Manager wizard to copy the database from DesktopA to DesktopB. SQL Server is running on both PCs as a local system
account (I think, how do I check?). When I start the wizard, it says
(local) for the source server and "use windows authentication", the
next step asks for the destination server and lists (local) and
DESKTOPB, when I pick DESKTOPB and either Windows and SQL
authentication I get the error message, "Cannot connect to the server
DESKTOPB. Please check the server name and try again." I am new to this so any ideas of what I should try would be appreciated. I don't know if I need to "register" the servers or anything else I might be leaving
out.


Jul 23 '05 #7
<rc*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Oh, you mean keep the database as an Access MDB.
No.
I mean keep the front end as an access mdb and convert the back end to sql
server.

Then attach the tables from the sql server to the access md.
This uses ODBC with a dsn to specify server etc.
Keep the same structure and names and this can mean no (other) changes to
the front end mdb.
If you're thinking front end mdb???
You want to search on google for splitting access databases.
Front end mdb goes on each end user pc and contains all the code bits.
Back end sits on server and contains all the data.

Re-writing as an adp is NOT as simple as just pushing a button.
Can be a tricky bit of work revisiting every screen.
I would question whether that work is really justified.
If that's what you
mean, I know what you mean, I like and prefer Access and I think it can
handle quite a lot but in this case I don't have a choice, everything
else is in SQL and it seems to be best to keep all the databases
consistent.

ADP as opposed to what? I mean, what GUI front end for the SQL

Server
database?

Also, I have SQL Server 2000 evaluation version on DesktopA and the
same SQL Server version running on DesktopB. I would like to use the
SQL Server Enterprise Manager wizard to copy the database from

DesktopA
to DesktopB. SQL Server is running on both PCs as a local system
account (I think, how do I check?). When I start the wizard, it says
(local) for the source server and "use windows authentication", the
next step asks for the destination server and lists (local) and
DESKTOPB, when I pick DESKTOPB and either Windows and SQL
authentication I get the error message, "Cannot connect to the server
DESKTOPB. Please check the server name and try again." I am new to

this
so any ideas of what I should try would be appreciated. I don't know

if
I need to "register" the servers or anything else I might be leaving
out.


Why move the database?
You realise you want to have just one database for an application, rather
than one on each desktop?

Dunno why you can't see the other machine, are you logging onto them using
the same user ?
Will that have authority enough?

Alternatively.
Back up and restore or sp_detach, copy the database files and sp_attach.
--
Regards,
Andy O'Neill
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Raghuraman | last post by:
Hai I have a designed Crystal report .rpt file which has 4 access tables .. After designing the report i put a parameter field which filteres...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are...
15
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size...
92
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why...
13
by: Greg Strong | last post by:
Hello All, Hello All, What are the ToDo's / Gotchas to convert an MDB Access 2K2 database to an Access Project (i.e. ADP) file for the front...
11
by: Steve Jorgensen | last post by:
I'm working on an application in Access 2002, and every time I'm done making changes in the VBA project, the database is noticeably larger after...
22
by: Jordan S. | last post by:
SQL Server will be used as the back-end database to a non trivial client application. In question is the choice of client application: I need...
16
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the...
10
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.