Dialog form Linked To Report

A

Aamer

I have created a dialog form, on this form I select the company name from the
dropdown list.
when a company name is selected, then the report should be generated.

presently I have a button on the form when i click on it the macro is set to
propt the dialog where i have to type the name of the company, if the company
name is wrong the report opens with no values, if the company name is right
then I get the report.

whereas what i want is insted of button I should have the List Box with
company names. Which I have created. But am stuck linking this form with the
report Name "General Purchase".


e.g. If i select company name "Coca Cola" in the list box it should give the
report of coca cola only


thanks & merry x-mas to all

aamer
 
A

Arvin Meyer [MVP]

Hopefully, you should have the ID of Coca Cola in the list box as a bound
field. Substituting your names, add a button to the form that opens the
report, with the following code:

DoCmd.OpenReport "Your Report Name", , , "CompanyID = " & Me.lstCompanyID
 
A

Aamer

it did not work

I am selecting company name field name is "pur companyname"
no its not looking with customer id
report name is "General Purchase"

I have tried the following:

DoCmd.OpenReport "General Purchase", , , "pur companyname = " & Me.lstpur
companyname

but its not woking.
can you pls fix it.

regards
aamer
 
J

John W. Vinson

it did not work

I am selecting company name field name is "pur companyname"
no its not looking with customer id
report name is "General Purchase"

I have tried the following:

DoCmd.OpenReport "General Purchase", , , "pur companyname = " & Me.lstpur
companyname

but its not woking.
can you pls fix it.

Two problems that I see: for one, you (unwisely) used a blank in the
fieldname. If you use blanks or other special characters in fieldnames you
must enclose the fieldname in square brackets. In addition, if you're
searching for a text company name, you must include the syntactically required
quotemarks. Since a company name might contain an apostrophe (Joe's Diner for
example) you must delimit with doublequotes; to include a doublequote in a
string delimited with doublequotes, you must use TWO doublequotes. Try

DoCmd.OpenReport "General Purchase", , , "[pur companyname] = """ _
& Me.[lstpur companyname] & """"
 
A

Arvin Meyer [MVP]

You did not use the CompanyID field. Instead you used a text field. John
Vinson corrected your code to get it to work, but It still makes more sense
to back up and use the ID (long integer data type) and the code methodology
I showed. Always use an indexed primary key instead of data to do lookups.
It probably doesn't make much difference with a few records, but it does
with thousands, and learning to do it correctly makes it work with
everything.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
A

Aamer

I have No idea why this code is still not working.

let me explain what I did

1. Created a popup form "Dialog General Purchase"
2. Placed a List Box which collects the Company Names from "General Purchase
Detail Querry" The feild for Company name is "Pur CompanyName" Grouped them
so they are not duplicated.
3. Placed a Button on the "Dialog General Purchase" Form
4. in the properties of the button on clik i cliked on CODE BUILDER and
entered the following code.

DoCmd.OpenReport "General Purchase Detail", , , "[pur companyname] = """ _
& Me.[lstpur companyname] & """"

after i do the above it still gives me error.



John W. Vinson said:
it did not work

I am selecting company name field name is "pur companyname"
no its not looking with customer id
report name is "General Purchase"

I have tried the following:

DoCmd.OpenReport "General Purchase", , , "pur companyname = " & Me.lstpur
companyname

but its not woking.
can you pls fix it.

Two problems that I see: for one, you (unwisely) used a blank in the
fieldname. If you use blanks or other special characters in fieldnames you
must enclose the fieldname in square brackets. In addition, if you're
searching for a text company name, you must include the syntactically required
quotemarks. Since a company name might contain an apostrophe (Joe's Diner for
example) you must delimit with doublequotes; to include a doublequote in a
string delimited with doublequotes, you must use TWO doublequotes. Try

DoCmd.OpenReport "General Purchase", , , "[pur companyname] = """ _
& Me.[lstpur companyname] & """"
 
J

John W. Vinson

I have No idea why this code is still not working.

let me explain what I did

1. Created a popup form "Dialog General Purchase"
2. Placed a List Box which collects the Company Names from "General Purchase
Detail Querry" The feild for Company name is "Pur CompanyName" Grouped them
so they are not duplicated.
3. Placed a Button on the "Dialog General Purchase" Form
4. in the properties of the button on clik i cliked on CODE BUILDER and
entered the following code.

DoCmd.OpenReport "General Purchase Detail", , , "[pur companyname] = """ _
& Me.[lstpur companyname] & """"

after i do the above it still gives me error.

I'm in full agreement with Arvin that you should *not* use the company name as
the linking field. Company names change, and can duplicate other companies'
names. You really should follow his good advice and use a unique meaningless
numeric ID as the company ID (behind the scenes, not shown to users).

Without seeing the Recordsource and Bound Column properties of the listbox
[lstpur companyname] and knowing more about the tables (e.g. is [pur
companyname] a Lookup field?) it's hard to advise... but I'd listen to Arvin
if I were you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top