Go Back   Access World Forums > Microsoft Access Discussion > Reports

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-25-2019, 05:11 AM   #1
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 41
Thanks: 19
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
open report with 2 conditions

Hi specialists,

I want to open a repport with 2 conditions.

part of the code :

Code:
DoCmd.OpenReport "Alle Dossiers", acViewPreview, , "[NN] =" & NN And "[Datum TA] =#" & [Datum TA] & "#"
Only with the "NN" condition, no problem.

[Datum TA] is a combobox to filter my form based on the date in that combobox.

When I want to open my report access gives me a error 13: Types don't match.

My form is based on a Query and the combox values are from the same Query.

Filtering in my form with that combobox is no problem.

He gives a error when I want to use that combobox value as condition.

What am I doeing wrong?

Thanks

Greetz

Pascal

scallebe is offline   Reply With Quote
Old 08-25-2019, 05:30 AM   #2
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,033
Thanks: 65
Thanked 2,560 Times in 2,457 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: open report with 2 conditions

maybe this will help:

DoCmd.OpenReport "Alle Dossiers", acViewPreview, , "[NN] =" & NN And "[Datum TA] =#" & Format(CDate([Datum TA]), "mm/dd/yyyy") & "#"
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 08-25-2019, 05:31 AM   #3
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,107
Thanks: 110
Thanked 2,749 Times in 2,508 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: open report with 2 conditions

You need to reference your form controls not the field names e.g. TxtNN, cboDatum.
Also strongly recommend you don't leave spaces in field or control names.

Is the bound field (usually hidden) of your combo a date field?
If not you need to reference the column number.
As the numbering starts at zero, you would need something like Me.[DatumTA].Column(1) for the second column in your combo

So
Code:
DoCmd.OpenReport "Alle Dossiers", acViewPreview, , "[NN] =" & Me.NN & " And [Datum TA] =#" & Me.[Datum TA].Column(1) & "#"
Or if you rename as suggested, you can omit all []
Code:
DoCmd.OpenReport "AlleDossiers", acViewPreview, , "NN =" & Me.TxtNN & " And DatumTA =#" & Me.cboDatumTA.Column(1) & "#"

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 08-25-2019, 06:45 AM   #4
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 41
Thanks: 19
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: open report with 2 conditions

hi,
Thanks for reply...

#arnelgp : your code didn't work

#isladogs : I followed your recommendations, renamed my fields and removed the spaces. I left NN like it was because I had no problem there.

My date is in Column 0 so de column number is not needed (I think)

this is my code :

Code:
DoCmd.OpenReport "Alle Dossiers", acViewPreview, , "NN =" & Me.NN & " And DatumTA =#" & Me.cboDatumTA & "#"
And now I have a empty report.

The strange thing is when I create a new Query and put the 2 criteria in the query fields (refering to my form fields) then I see what I want. The goal is of cource to work with one repport and one Query, filtered with some VBA

Thank you all

Greetz
scallebe is offline   Reply With Quote
Old 08-25-2019, 07:00 AM   #5
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,107
Thanks: 110
Thanked 2,749 Times in 2,508 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: open report with 2 conditions

OK. No type mismatch errors so NN is a number field and DatumTA is a date field.
Next thing to check are the control names on the form are definitely NN and cboDatumTA. If not either rename them or modify the code line.
Also check that the bound column of the combo is the DatumTA field.
If not, you do need to use .Column(0)

FWIW you forgot to rename your report without spaces.

EDIT If your default date format isn't mm/dd/yyyy then you need to format your sql string as arnelgp suggested

Code:
DoCmd.OpenReport "AlleDossiers", acViewPreview, , "NN =" & Me.TxtNN & " And DatumTA =#" & Format(Me.cboDatumTA,"mm/dd/yyyy") & "#"
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 08-25-2019 at 07:14 AM.
isladogs is offline   Reply With Quote
Old 08-25-2019, 07:48 AM   #6
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 41
Thanks: 19
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: open report with 2 conditions

#arnelgp and #isladogs,

The combination of your suggestions did it... Finally

This is my final working code :

Code:
DoCmd.OpenReport "AlleDossiers", acViewPreview, , "NN =" & Me.NN & " And DatumTA =#" & Format(CDate([DatumTA]), "mm/dd/yyyy") & "#" '=#" & Me.cboDatumTA.Column(0) & "#"
Thanks also for your tips, sometimes I have the bad habit to work with spaces, format my field names in a bad way, (cbo, txt,....)

I still have so much to learn.

Thanks, and enjoy the rest of the weekend.
scallebe is offline   Reply With Quote
Old 08-25-2019, 08:44 AM   #7
Gasman
Enthusiastic Amateur
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 3,992
Thanks: 418
Thanked 716 Times in 695 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: open report with 2 conditions

That actually works?

Code:
DoCmd.OpenReport "AlleDossiers", acViewPreview, , "NN =" & Me.NN & " And DatumTA =#" & Format(CDate([DatumTA]), "mm/dd/yyyy") & "#" '=#" & Me.cboDatumTA.Column(0) & "#"
Quote:
Originally Posted by scallebe View Post
#arnelgp and #isladogs,

The combination of your suggestions did it... Finally

This is my final working code :

Code:
DoCmd.OpenReport "AlleDossiers", acViewPreview, , "NN =" & Me.NN & " And DatumTA =#" & Format(CDate([DatumTA]), "mm/dd/yyyy") & "#" '=#" & Me.cboDatumTA.Column(0) & "#"
Thanks also for your tips, sometimes I have the bad habit to work with spaces, format my field names in a bad way, (cbo, txt,....)

I still have so much to learn.

Thanks, and enjoy the rest of the weekend.

__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 08-25-2019, 09:20 AM   #8
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,107
Thanks: 110
Thanked 2,749 Times in 2,508 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: open report with 2 conditions

As Gasman indicated that cannot work
Hopefully you just copied and pasted incorrectly in your last answer.

My previous answer should have worked...with the possible addition of .Column(0) if ne essary
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 08-25-2019, 10:10 AM   #9
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 41
Thanks: 19
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: open report with 2 conditions

My mistake

This is the working code :

Code:
DoCmd.OpenReport "AlleDossiers", acViewPreview, , "NN =" & Me.NN & " And DatumTA =#" & Format(CDate([DatumTA]), "mm/dd/yyyy") & "#"
There is no reference to the combobox anymore with this code correct?


Greetz

Pascal
scallebe is offline   Reply With Quote
Old 08-25-2019, 10:29 AM   #10
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,107
Thanks: 110
Thanked 2,749 Times in 2,508 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: open report with 2 conditions

Not correct. As previously stated, always reference the form controls not the fields

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
scallebe (08-26-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
open a form with conditions scallebe Forms 16 08-12-2019 02:40 AM
Open Form WHERE conditions Snowflake68 Modules & VBA 2 11-30-2016 06:17 AM
Open report with three conditions JRPMD Visual Basic 3 11-25-2012 06:46 PM
Open report with conditions JRPMD Reports 1 11-24-2012 11:07 PM
Open form on All conditions met NigelShaw General 8 02-11-2008 02:34 PM




All times are GMT -8. The time now is 09:05 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World