473,395 Members | 2,006 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,395 software developers and data experts.

Filtering a sub form based on information located in a completely different table

I am completely new to Access. I received some great help with another question I had so I was hoping to get some assistance with another. I have never coded before I started this project so I apologize, my verbage and usage of the information you give me may be in correct and I hope you can be patient with me. Thank you for anyone's time who gives me advice!

I have a reminder form that I created to remind any user who accesses the database about certain criteria not being met. For example, my Initial Survey Reminder uses code that counts how many invoices have the Survey box checked but no Sent date entered. The code then uses that number to let the user know, on the form, that there are X amount of invoices that need a survey sent. I originally had a very large table with all of my information stored on it but because of how large it got I rearranged my data in multiple tables. The problem I have is that before I rearranged I was able to insert a subform of my database form so that when they clicked on a button the form would filter to the the companies that had this criteria. Now that I have rearranged the information I was wondering if there was still a way to do this. All of my Tables have relationships to the main table. I would like for buttons to open the main form (it doesn't have to be the subform if it is better to just open the form) to these companies. I have and the relationship between Form FrmDatabaseInformation (Main Form) and Form frmInvoiceTracking is a one to many between the CompanyId fields.

In my Form FrmReminders here is the code I had on Load:

Expand|Select|Wrap|Line Numbers
  1. Dim InitialSurvey As Integer
  2. InitialSurvey = DCount("*", "TblInvoiceTracking", "[Survey] = Yes AND [Sent Date] Is Null")
  3. Me.FrmDatabaseInformation.Visible = False
  4. If InitialSurvey > 0 Then
  5. Me.lblInitialSurvey.Caption = "There are " & InitialSurvey & " Initial Surveys that need to be sent!"
  6. Me.lblInitialSurvey.ForeColor = vbRed
  7. Me.lblInitialSurvey.FontWeight = 700
  8.  
  9. ElseIf InitialSurvey = 0 Then
  10. Me.lblInitialSurvey.Caption = "No Outstanding Reminders"
  11. Me.lblInitialSurvey.ForeColor = vbBlack
  12. Me.lblInitialSurvey.FontWeight = 400
  13.  
  14. End If 
And this is the code I had previously on the button that should filter the subreport
Expand|Select|Wrap|Line Numbers
  1. Private Sub InitialSurveyCommand_Click()
  2.  
  3. Me.FrmDatabaseInformation.Form.Filter = "[Survey] = Yes AND [Sent Date] Is Null"
  4. Me.FrmDatabaseInformation.Form.FilterOn = True
  5. Me.FrmDatabaseInformation.Visible = True
  6.  
  7. End Sub
Any help is greatly appreciated, have a wonderful day!
Jan 13 '17 #1

✓ answered by zmbd

Sorry for the long pause here, things have been extremely busy and I just have been pulled in 100 directions :(

I am hoping, despite my delay, that you've resolved this issue; however, I really do not like leaving a thread unresolved... not my best work.

In your Original code you had the filter string formatted correctly and you set the filter property of the form to true, you need to do that same kind of thing here after the form opens.

I usually use the named parameters method of writing code, a bit slower to type; however, you don't have to worry about the commas ( :-) ), the next person reading the code clearly understands what you're doing, and I also tend to form my strings first so that one can troubleshoot them later.

There appears to be an issue with
Me.CompanyID & = & CompanyID
you have a reference to the form control which will return the value of the data in that control (me.companyid) compared to a variable defined somewhere within your code. Did you intend:
"CompanyID=" & Me.CompanyID

So that we could have something like:
Expand|Select|Wrap|Line Numbers
  1.    Dim strWhereSQL As String
  2.    strWhereSQL  = "CompanyID=" & Me.CompanyID
  3. '<>
  4. 'Troubleshooting, run code, press <ctrl><g> to review the string
  5. Debug.print strWhereSQL
  6. '
  7. '<>
  8.    DoCmd.OpenForm FormName:="FrmDatabaseInformation", _
  9.       WhereCondition:=strWhereSQL, _
  10.       WindowMode:=acDialog
  11. 'I've omitted the window mode as the default is acNormal
  12. '
  13. 'Here, I'm not sure if you wanted the following code in the command button still or filter on open
  14. '
  15.    Me.SubformName.Filter = "[Survey] = True AND [Send Date] is Null"
  16. 'Added a closing quote to the string.
  17. '
  18.    Me.FilterOn = True
Of course, all of the comment lines would be removed in your final code along with line 5. :)

5 1089
zmbd
5,501 Expert Mod 4TB
It sounds as if you have been sabotaged by the non-normalization Gremlin. - Don't worry, I've been beaten up by him too in my early design days, have you taken a look at
home > topics > microsoft access / vba > insights > database normalization and table structures

Once you have your database properly normalized, then you should be able to create a query against the related tables that pulls your data out, with any luck, you might be able to still use your form with little if any changes.

We'll need a bit more information about your tables and how the data is related between them. For now I think that all we should need is something like:

[table_1]
[table_1].[PrimaryKey]

[table_2]
[table_2].[PrimaryKey]
[table_2].[ForeignKey_table_1]

I use PK as short for primary key and FK for foreign key when naming fields :)

I am going to locate your other thread and read through that to see what else I can learn about your database. This may take me a little bit to do and I have an obligation tonight :)

In the meantime, I'm also going to PM you a copy of a boilerplate with some links to tutorials and other hopefully useful information to keep in your toolbox as you progress.
> Your Bytes.com Inbox <
Jan 21 '17 #2
zmbd,

Thank you very much! I will be unable to look through all of the references you have given me tonight due to time constraints but I have already saved them and can see, by skimming, that many of the information should prove very useful!
Also, thank you for taking the time to respond, I would like to try and answer your question regarding the primary keys and foreign keys but forgive me if it is in accurate, I will edit once I have the time to look through the data you sent.

Each of my tables has a primary key set up with an Autonumber field. In the cases of tables that have a 1 to many relation ship I have added a foreign key (I think is the terminology) that is just a simple numbered field. To use your example,
TblDatabaseInformation
primary key [CompanyID]

TblInvoiceTracking
primary key [InvoiceID]
foreign key [CompanyID]

(though I am unsure if I need to mark the foreign key as anything, right now it is just a column) This field is not marked as required. In my form I used some code in order to pull the CompanyID from the main form to the corresponding new invoice as it is entered.

In my reminders form the dcount uses the TblInvoiceTracking but I haven't been able to figure out how to open the main database with a filter based on the criteria in a different table.

I hope this helps while you take a look at my other post. Again, thank you for your time. I will look at what you sent me as soon as I have some time. Have a great day!
Jan 23 '17 #3
So I did look through the information you sent me and while some of it went over my head I think I understand what you were talking about in regards to normalization. I did check that all of my data was stored correctly and the only thing I may have a slight bit of trouble is in regards to my FrmDatabaseInformation and my FrmAdditionalContacts both having addresses entered. I do need this information separate and the data has not been entered twice, the address in FrmDatabaseInformation and in FrmAdditionalContacts are different. Maybe I can rephrase my question and if there is a way around this that would be amazing.

I am able to filter the survey information I need by using the TblInvoices table and filtering to get the number of surveys that need sent. What I would like to be able to do is to open my FrmDatabaseInformation, or subform if I can, to open to the Companies that correspond with the invoices that meet that criteria. I have used the where portion of an DoCmd.OpenForm before and it worked but I am not sure how to get the filter to run. I thought the code could look something like this but I am not sure.

Expand|Select|Wrap|Line Numbers
  1. Me.SubformName.Filter = "[Survey] = True AND [Send Date] is Null
  2. DoCmd.OpenForm "FrmDatabaseInformation", AcNormal, WHERE: Me.CompanyID & = & CompanyID
  3.  
I put the Where because I couldn't remember how many commas before the where option.
Something along those lines but I don't have access to my database today (working from home) to make sure my syntax is correct. Thank you for your time!
Feb 1 '17 #4
zmbd
5,501 Expert Mod 4TB
Sorry for the long pause here, things have been extremely busy and I just have been pulled in 100 directions :(

I am hoping, despite my delay, that you've resolved this issue; however, I really do not like leaving a thread unresolved... not my best work.

In your Original code you had the filter string formatted correctly and you set the filter property of the form to true, you need to do that same kind of thing here after the form opens.

I usually use the named parameters method of writing code, a bit slower to type; however, you don't have to worry about the commas ( :-) ), the next person reading the code clearly understands what you're doing, and I also tend to form my strings first so that one can troubleshoot them later.

There appears to be an issue with
Me.CompanyID & = & CompanyID
you have a reference to the form control which will return the value of the data in that control (me.companyid) compared to a variable defined somewhere within your code. Did you intend:
"CompanyID=" & Me.CompanyID

So that we could have something like:
Expand|Select|Wrap|Line Numbers
  1.    Dim strWhereSQL As String
  2.    strWhereSQL  = "CompanyID=" & Me.CompanyID
  3. '<>
  4. 'Troubleshooting, run code, press <ctrl><g> to review the string
  5. Debug.print strWhereSQL
  6. '
  7. '<>
  8.    DoCmd.OpenForm FormName:="FrmDatabaseInformation", _
  9.       WhereCondition:=strWhereSQL, _
  10.       WindowMode:=acDialog
  11. 'I've omitted the window mode as the default is acNormal
  12. '
  13. 'Here, I'm not sure if you wanted the following code in the command button still or filter on open
  14. '
  15.    Me.SubformName.Filter = "[Survey] = True AND [Send Date] is Null"
  16. 'Added a closing quote to the string.
  17. '
  18.    Me.FilterOn = True
Of course, all of the comment lines would be removed in your final code along with line 5. :)
Mar 11 '17 #5
zmbd,

Thank you very much for replying. I did find something that worked for me and it is similar to what you suggested. I do not have access to my database to show you exactly what I did but I used a series of hidden queries that became visible when the correct button was selected, with each button it filtered the queries to the correct companies. Lastly, when you select the company from the list it opens to that company in the database. It was not exactly as I had hoped for but it works out for my company for now. Thank you again and I will use the information you have provided for any future work I have. Have a wonderful day!
Mar 13 '17 #6

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
4
by: sheree | last post by:
I have 3 tables (amoung a few others) in a small access database. The tables are as follows: == AEReport -------- AEID (PK) RptCatelog GCRCID PatientID EvntDate
1
by: David Boone | last post by:
Please excuse the newbie questions, but I'm fairly new to Access though familiar with databases in general (experience with MySQL and PostgreSQL). The basic idea is that there is table of...
13
by: david | last post by:
I can not figure out what is the problem that I can protect ASP.NEt form resource but not some other type of files, for example, images. All my aspx forms located in Demo folder and image files...
4
by: Deus402 | last post by:
Here is my table design: tblEmployers EmployerID autonum (primary key) EmployerName text tblLocations LocationID autonum (primary key) EmployerID longint (foreign key) LocationAdress text
5
by: SeanCly10 | last post by:
Hi all. I don't want to sound like a complete idiot here, but I'm somewhat limited in my coding knowledge, and I need some advice and help. I'm working on a database that will eventually be used...
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
4
by: novoselent | last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong... Using Access 2003 I have a form that lists vehicle service...
1
by: Dean0621 | last post by:
Good morning folks, as with most people on here with their first time question, I have been working on this issue for nearly two weeks, doing some searching on this forum and the internet to assist...
1
by: hellosanto | last post by:
How to insert the single form value to the two different table in the database ? one is personnel information table and another is signup table
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.