473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

help with complicated query?

AccessIdiot
493 256MB
I have three tables and three forms:
1) tbl_Survey (frm_Survey, page 1 of a tab control) has Survey_ID primary key and field Survey_Num
2) tbl_Replicate (sbfrm_Replicate, subform of frm_Survey and page 2 of a tab control) has Replicate_ID primary key, Survey_ID foreign key, and field Replicate_Num
3) tbl_Specimen_Replicate (frm_Specimen_Replicate) has Specimen_ID as primary key and Replicate_ID as a foreign key

So in other words:
tbl_Survey <--- one to many --> tbl_Replicate < --- one to many ---> tbl_Specimen_Replicate

On frm_Specimen_Replicate I would like to have a textbox that shows a concatenation of the Survey_Num and Replicate_Num and I'm not quite sure how to do that. I tried to make the control source of the textbox a sql query but that didn't pan out well. I also tried to use VBA code on the form current event but it didn't like that either. Probably because my code sucks:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "SELECT tbl_Survey.Survey_Num, tbl_Replicate.Replicate_Num FROM (tbl_Survey INNER JOIN tbl_Replicate ON tbl_Survey.Survey_ID = tbl_Replicate.Survey_ID) INNER JOIN tbl_Specimen_Replicate ON tbl_Replicate.Replicate_ID = tbl_Specimen_Replicate.Replicate_ID;"
Well maybe the code isn't that bad but it's not really a concatenation - it's just a select statement.

Any ideas how I can pull this off?

Thanks!
Apr 27 '07 #1
14 1500
Rabbit
12,516 Expert Mod 8TB
tbl_Specimen_Replicate has the Replicate number so that's no problem. You just need to look up the Survey Number from the Replicate table. Use DLookup for that.
Apr 27 '07 #2
AccessIdiot
493 256MB
So I should stick with the VBA code on current form, then use DLookup to get the Survey Num, do a select statement to get the Rep Num, and then do a concatenate?

Is it possible to create a variable that you set to the value of the Select statement?
Apr 27 '07 #3
Rabbit
12,516 Expert Mod 8TB
So I should stick with the VBA code on current form, then use DLookup to get the Survey Num, do a select statement to get the Rep Num, and then do a concatenate?

Is it possible to create a variable that you set to the value of the Select statement?
You don't need SQL at all, I assume the form is bound to the table so you have access to that records Replicate Number without having to do anything special. DLookup will get your your Survey Number, then you can concatenate.

You don't even need VBA you can just set the control source using an expression.
Apr 27 '07 #4
AccessIdiot
493 256MB
Okay I'm struggling even with getting the survey number.

I have this:
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Survey_Num]","tbl_Survey_Num","[Survey_ID]= ")
but I'm not sure how to put in the criteria for getting the survey_id that is related to tbl_Replicate.Replicate_ID that is related to tbl_Specimen_Replicate.Replicate_ID.

That's why I thought I'd need SQL to do a join since tbl_Survey isn't directly related to tbl_Specimen_Replicate but only through tbl_Replicate which has both Survey_ID and Replicate_ID.

Confusing yes?
Apr 27 '07 #5
Rabbit
12,516 Expert Mod 8TB
Okay I'm struggling even with getting the survey number.

I have this:
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Survey_Num]","tbl_Survey_Num","[Survey_ID]= ")
but I'm not sure how to put in the criteria for getting the survey_id that is related to tbl_Replicate.Replicate_ID that is related to tbl_Specimen_Replicate.Replicate_ID.

That's why I thought I'd need SQL to do a join since tbl_Survey isn't directly related to tbl_Specimen_Replicate but only through tbl_Replicate which has both Survey_ID and Replicate_ID.

Confusing yes?
You're going about it the wrong way. You shouldn't be getting the Survey number from tbl_Survey_Num but from tbl_Replicate where the Replicate_ID is equal to the Replicate_ID in your tbl_Specimen_Replicate which you have access to.
Apr 27 '07 #6
AccessIdiot
493 256MB
Oh of course! Why didn't I think of that? Let me give it shot. :)
Apr 27 '07 #7
AccessIdiot
493 256MB
You're going about it the wrong way. You shouldn't be getting the Survey number from tbl_Survey_Num but from tbl_Replicate where the Replicate_ID is equal to the Replicate_ID in your tbl_Specimen_Replicate which you have access to.
No wait, I can't get the Survey_Num from tbl_Replicate - tbl_Replicate contains the Survey_ID but not the Survey_Num. Survey_Num only exists in tbl_Survey.

Or can I?

tbl_Survey
Survey_ID
Survey_Num

tbl_Replicate
Replicate_ID
Survey_ID

tbl_Specimen_Replicate
Replicate_ID

I've only seen examples of the DLookup function that involves two tables or forms, not three?
Apr 27 '07 #8
Rabbit
12,516 Expert Mod 8TB
No wait, I can't get the Survey_Num from tbl_Replicate - tbl_Replicate contains the Survey_ID but not the Survey_Num. Survey_Num only exists in tbl_Survey.

Or can I?

tbl_Survey tbl_Replicate tbl_Specimen_Replicate
Survey_ID Replicate_ID Replicate_ID
Survey_Num Survey_ID


I've only seen examples of the DLookup table that involves two tables or forms, not three?
Well.. I suppose you could embed DLookups.
Expand|Select|Wrap|Line Numbers
  1. DLookup("Survey_Num", "tbl_Survey", "Survey_ID = " & DLookup(...))
Apr 27 '07 #9
AccessIdiot
493 256MB
Tried this:
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[Survey_Num]","[tbl_Survey]","[Survey_ID] = " & DLookUp("[Survey_ID]","[tbl_Replicate]","[Replicate_ID]=Forms![frm_Specimen_Replicate]![Replicate_ID]"))
and got #Error

Is my formatting wrong?
Apr 27 '07 #10
Rabbit
12,516 Expert Mod 8TB
Looks perfectly fine. Everything's a number correct?
Apr 27 '07 #11
AccessIdiot
493 256MB
Okay so instead I have done this and got the Survey_Num just fine:
Expand|Select|Wrap|Line Numbers
  1. =Forms!frm_Survey!Survey_Num
But it didn't like the concatenation I tried:
Expand|Select|Wrap|Line Numbers
  1. =Forms!frm_Survey!Survey_Num & Forms!sbfrm_Replicate!Replicate_Num
Do I need quote marks for the concatenation or something?
Apr 27 '07 #12
Rabbit
12,516 Expert Mod 8TB
Okay so instead I have done this and got the Survey_Num just fine:
Expand|Select|Wrap|Line Numbers
  1. =Forms!frm_Survey!Survey_Num
But it didn't like the concatenation I tried:
Expand|Select|Wrap|Line Numbers
  1. =Forms!frm_Survey!Survey_Num & Forms!sbfrm_Replicate!Replicate_Num
Do I need quote marks for the concatenation or something?
That works as long the forms are open and are synced to the same record.

Is sbfrm_Replicate a subform? Because the syntax for that is [Forms]![MainForm]![SubForm].Form.ControlName
Apr 27 '07 #13
AccessIdiot
493 256MB
Yep I JUST figured that out!

Expand|Select|Wrap|Line Numbers
  1. =Forms!frm_Survey!Survey_Num & Forms!frm_Survey!sbfrm_Replicate!Replicate_Num
works perfectly!

Thanks Rabbit :D
Apr 27 '07 #14
Rabbit
12,516 Expert Mod 8TB
Not a problem.
Apr 27 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
6
by: Martin Hampl | last post by:
Hi, I am using PostgreSQL 7.4, but I did have the same problem with the last version. I indexed the column word (defined as varchar(64)) using lower(word). If I use the following query,...
2
by: William Wisnieski | last post by:
Hello Everyone Access 2000 Looking for some suggestions and advice on how to proceed with this. I hope its not as complicated as it seems to me right now. I've got an unbound main form...
5
by: Arvin Portlock | last post by:
I can't come up with a query that works. Can anyone help? Conceptually the relationships are easy to describe. I have a table for books (Entries), a table for authors (Authors), and a linking...
5
by: Norma | last post by:
I am trying to make a query pull data from between the dates I enter in the parameter but also look back 'in time' to see where 2 other fields have null values, and only pull data into the query if...
4
by: technobob | last post by:
I have what seems to be a strange situation. I have a table where Sales are recorded. Most of the time there is only a primary salesman involved (Salesman1). When there is a secondary salesman,...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: AdrianG | last post by:
I am trying to write a single SQL query that would retrieve the data that I need. For example, I have a table called Athletes that has 2 fields: name and sport containing the name of an athlete and...
3
by: william67 | last post by:
I'm having a hard time building a query to do what I need to do and was hoping some genius could help me out, I need to do a complex query and any and all help is much appreciated this is the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.