alejandro23
alejandro23

Reputation: 21

Access - Generate report using form with VB

I have this table (TABLE1).

Name | IDCard | Class
Aba     123      A 
Ebe     456      B
Ibi     789      C

I have this query (QUERY1)

SELECT Name, IDCard FROM TABLE1;

Then, in the Report Assistant I choose QUERY1, I open the report generated, and it shows all the names and IDCards from TABLE1.

So now I create a form with a ComboBox called NameStudents and a button to preview the result.

Finally I open VB to code a filter for the report with the selected name like this:

DoCmd.OpenReport stDocName, acPreview, , "[Name] =" & Me!NameStudents

I simply want a form that selects names from a table and puts them in a Combobox, then the user selects one student, clicks preview, and a report will appear with name and IDCard.

I don't know why this doesn't work. Thank you very much.

Upvotes: 2

Views: 901

Answers (1)

BIBD
BIBD

Reputation: 15384

The question I would have is what happens when you hard code the name?

DoCmd.OpenReport stDocName, acPreview, , "[Name] = John"

I have this feeling that your names actually have spaces in it, like this:

DoCmd.OpenReport stDocName, acPreview, , "[Name] = John Smith" 

In which case, you might have to do this

DoCmd.OpenReport stDocName, acPreview, , "[Name] = ""John Smith""" 

or

DoCmd.OpenReport stDocName, acPreview, , "[Name] = """ & Me!NameStudents & """"

Upvotes: 1

Related Questions