Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > DoCmd.OpenReport with nested sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-03, 05:16
vb-wanna-b vb-wanna-b is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
DoCmd.OpenReport with nested sql

Im trying to make openreport button that selects a number of records from one table based on a compare in another. I have made an sql call in query mode that gives me the records that I want to make a report from, but I cannot convert it to vba. any pointer, solutions or heads-up are welcome


DoCmd.OpenReport strDocName, acViewPreview, , "SELECT support.SerieNr FROM support WHERE support.SerieNr IN (SELECT SerieNr FROM IT_tilmeld WHERE AfdNr = " & test)

I get a compile error when I use (), and no errors without, but the statement will not work...
Reply With Quote
  #2 (permalink)  
Old 12-02-03, 08:19
Marvels Marvels is offline
Registered User
 
Join Date: Jul 2003
Location: Amsterdam, Nederland
Posts: 433
Lightbulb try LIKE operator

The error u get is because theres an corversion type error
(vergelijking zijn van verschillende typen, je vergelijkt tekst waar men een nummer verwacht)
solution :


or do :
WHERE AfdNr LIKE " & test)


or :
WHERE AfdNr = " & 9)

(IS nummer of ziet er uit ALS tekst :-)

IS =
ALS LIKE
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 09:58
vb-wanna-b vb-wanna-b is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
not sure what you mean by & 9 ??

anyway I have tried it out, but that didnt do the trick either
Reply With Quote
  #4 (permalink)  
Old 12-02-03, 10:17
sivaroo sivaroo is offline
Registered User
 
Join Date: Nov 2003
Posts: 76
Try the SQL below

DoCmd.OpenReport strDocName, acViewPreview, ,("SELECT support.SerieNr FROM support WHERE support.SerieNr LIKE (SELECT SerieNr FROM IT_tilmeld WHERE AfdNr like " & test))
Reply With Quote
  #5 (permalink)  
Old 12-02-03, 10:21
vb-wanna-b vb-wanna-b is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
nope..still getting a syntax error on the )
Reply With Quote
  #6 (permalink)  
Old 12-02-03, 10:56
Marvels Marvels is offline
Registered User
 
Join Date: Jul 2003
Location: Amsterdam, Nederland
Posts: 433
if your field SerieNr AND AfdNr are numbers use

dim test as integer
test = 1
NOTE1 : the dim statements is an example just to make it clear, i hope

DoCmd.OpenReport strDocName, acViewPreview, ,
("SELECT support.SerieNr
FROM support
WHERE support.SerieNr = (SELECT SerieNr FROM IT_tilmeld WHERE AfdNr = " & test))




if your field SerieNr is number AND AfdNr is text use

dim test as String
test = "Front Office"

DoCmd.OpenReport strDocName, acViewPreview, ,
("SELECT support.SerieNr
FROM support
WHERE support.SerieNr = (SELECT SerieNr FROM IT_tilmeld WHERE AfdNr LIKE ' " & test & "'" ))


NOTE2 : LIKE ' " & test & "'" equals
LIKE ' " & test & " ' "
Reply With Quote
  #7 (permalink)  
Old 12-02-03, 14:47
buchokoy buchokoy is offline
Registered User
 
Join Date: Oct 2002
Location: Philippines
Posts: 15
Re: try LIKE operator

Quote:
Originally posted by Marvels
The error u get is because theres an corversion type error
(vergelijking zijn van verschillende typen, je vergelijkt tekst waar men een nummer verwacht)
solution :


or do :
WHERE AfdNr LIKE " & test)


or :
WHERE AfdNr = " & 9)

(IS nummer of ziet er uit ALS tekst :-)

IS =
ALS LIKE


check for duane's and shurik's reply at visualbasicforum
Reply With Quote
  #8 (permalink)  
Old 12-03-03, 18:35
vb-wanna-b vb-wanna-b is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
I finaly made it work..thanx for the inspiration...
the working solution looks like this

Dim test As String
Dim strDocName As String
Dim FilterCriteria As String

test = Me!AfdNr

strDocName = "Service_og_support_liste"


FilterCriteria = "SELECT DISTINCT [support].[ServiceNr] FROM support WHERE (((support.SerieNr) In (SELECT SerieNr FROM IT_tilmeld WHERE AfdNr = '" & test & "')))"

DoCmd.SetWarnings False
DoCmd.OpenReport strDocName, acViewPreview, FilterCriteria
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On