Ask Experts Questions for FREE Help !
Ask
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #1

    Jun 12, 2009, 06:14 AM
    Run-Time Error.
    Hi,

    I am using Access 2000.
    I have a form that shows all the projects being held inside my database.
    I have made drop down boxes in the form with VBA to filter the projects.
    I am getting an error when I try to filter the projects:

    Run Time Error '3079':
    The specified field 'FiscalYear' could refer to more than one table listed in the FROM clause of your SQL statement.

    What does this mean?
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Jun 12, 2009, 07:03 AM

    The message indicates that the compiler can't figure out which table you're trying to access. Is "FiscalYear" a column title in more than one table? As an experiment, you could change one of the "FiscalYear"s to "Fiscal_Year". If that works, then change it back and try to specify the table name more explicitly in the FROM clause.

    To be more specific, you're probably trying to say "SELECT ... FROM ... WHERE" and whatever you're trying to select is not unique.

    The syntax for fully qualified tables names is [server].[databasename].[owner].[table name].
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #3

    Jun 12, 2009, 07:09 AM
    Quote Originally Posted by Perito View Post
    The message indicates that the compiler can't figure out which table you're trying to access. Is "FiscalYear" a column title in more than one table? As an experiment, you could change one of the "FiscalYear"s to "Fiscal_Year". If that works, then change it back and try to specify the table name more explicitly in the FROM clause.

    To be more specific, you're probably trying to say "SELECT ... FROM ... WHERE" and whatever you're trying to select is not unique.

    The syntax for fully qualified tables names is [server].[databasename].[owner].[table name].
    Thank you very much. I just changed the name to Fiscal_Year and I no longer get the error.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #4

    Jun 12, 2009, 12:19 PM

    Perito is right about the error, but I think your solution may not the best choice. Rather than changing the name of a field, you would be better to fully qualify your field names.

    In Access a fully qualified names is just [tablename].[fieldname]. So somewhere in the SQL statement was the fieldname FiscalYear. All you need to do is indicate what table that instance of FiscalYear was looking at by prefacing it with the tablename. If you want to post your SQL statement we can suggest where to change it.
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #5

    Jun 15, 2009, 11:01 AM
    Quote Originally Posted by ScottGem View Post
    Perito is right about the error, but I think your solution may not the best choice. Rather than changing the name of a field, you would be better to fully qualify your field names.

    In Access a fully qualified names is just [tablename].[fieldname]. So somewhere in the SQL statement was the fieldname FiscalYear. All you need to do is indicate what table that instance of FiscalYear was looking at by prefacing it with the tablename. If you want to post your SQL statement we can suggest where to change it.
    I understand what your are saying but am still a little unsure of how to correct it in my sql statement. Again the error specifies it is in the FROM clause of my sql statement, however what fiscal year do I change.
    Here is my sql statement:

    'only Province, ProjectType and Status selected
    If (budgetItemsTemp = " ") And (fiscalYearTemp = " ") And (categoryTemp = " ") Then
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType " _
    & "FROM tblMain "

    'only cboBudgetItems and previous selected
    ElseIf (fiscalYearTemp = " ") And (categoryTemp = " ") Then
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblBudgetItems.BudgetItems " _
    & "FROM tblMain LEFT JOIN tblBudgetItems ON tblMain.ProjectCode = tblBudgetItems.ProjectCode "

    'only cboCategory and original three selected
    ElseIf (budgetItemsTemp = " ") And (fiscalYearTemp = " ") Then
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblCategory.PolicyArea, tblCategory.Priority, tblCategory.ScheduleAExceptions " _
    & "FROM tblMain LEFT JOIN tblCategory ON tblMain.ProjectCode = tblCategory.ProjectCode "

    'only cboFiscalYear and original three selected
    ElseIf (budgetItemsTemp = " ") And (categoryTemp = " ") Then
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblFiscalBudget.FiscalYear, tblFiscalBudget.Budget " _
    & "FROM tblMain LEFT JOIN tblFiscalBudget ON tblMain.ProjectCode = tblFiscalBudget.ProjectCode "

    ElseIf (fiscalYearTemp = " ") Then 'all except cboFiscalYear selected
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblBudgetItems.BudgetItems, tblCategory.PolicyArea, tblCategory.Priority, " _
    & "tblCategory.ScheduleAExceptions " _
    & "FROM (tblMain LEFT JOIN tblBudgetItems ON tblMain.ProjectCode = tblBudgetItems.ProjectCode) " _
    & "LEFT JOIN tblCategory ON tblBudgetItems.ProjectCode = tblCategory.ProjectCode "

    ElseIf (budgetItemsTemp = " ") Then 'all except cboBudgetItems selected
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblFiscalBudget.FiscalYear, tblFiscalBudget.Budget, tblCategory.PolicyArea, " _
    & "tblCategory.Priority, tblCategory.ScheduleAExceptions " _
    & "FROM (tblMain LEFT JOIN tblFiscalBudget ON tblMain.ProjectCode = tblFiscalBudget.ProjectCode) " _
    & "LEFT JOIN tblCategory ON tblFiscalBudget.ProjectCode = tblCategory.ProjectCode "

    ElseIf (categoryTemp = " ") Then 'all except cboCategory selected
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblFiscalBudget.FiscalYear, tblFiscalBudget.Budget, tblBudgetItems.BudgetItems " _
    & "FROM (tblMain LEFT JOIN tblBudgetItems ON tblMain.ProjectCode = tblBudgetItems.ProjectCode) " _
    & "LEFT JOIN tblFiscalYear ON tblBudgetItems.ProjectCode = tblFiscalYear.ProjectCode "

    Else 'everything selected
    sql = "SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, " _
    & "tblMain.ProjectType, tblFiscalBudget.FiscalYear, tblFiscalBudget.Budget, tblBudgetItems.BudgetItems, " _
    & "tblCategory.PolicyArea, tblCategory.Priority, tblCategory.ScheduleAExceptions " _
    & "FROM ((tblMain LEFT JOIN tblFiscalBudget ON tblMain.ProjectCode = tblFiscalBudget.ProjectCode) " _
    & "LEFT JOIN tblBudgetItems ON tblFiscalBudget.ProjectCode = tblBudgetItems.ProjectCode) " _
    & "LEFT JOIN tblCategory ON tblBudgetItems.ProjectCode = tblCategory.ProjectCode "
    End If
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #6

    Jun 15, 2009, 01:41 PM

    I can't see anywhere its not fully qualified. So you need to use Debug tools to step through the code and see WHICH SQL statement is causing the error.
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #7

    Jun 16, 2009, 06:13 AM
    Quote Originally Posted by ScottGem View Post
    I can't see anywhere its not fully qualified. So you need to use Debug tools to step through the code and see WHICH SQL statement is causing the error.
    Exactly I thought so to. So I debugged the error and it gives me a highlighted: 'Me.RecordSource = sql'
    This highlighted area is below the sql that I just posted. Then I assumed the error was somewhere in my sql but that is what I just posted and it doesn't look like anything is wrong.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #8

    Jun 16, 2009, 06:22 AM

    OK, You really need to learn how to use the Debug tools. In the VBE, there is a Locals window. In that window, its will show the current value of the sql variable. If you can't read the whole thing thing, then add a line:

    Debug.Print sql

    before the highlighted line and it will display the value of sql in the Immediate window.
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #9

    Jun 16, 2009, 07:23 AM
    Quote Originally Posted by ScottGem View Post
    OK, You really need to learn how to use the Debug tools. In the VBE, there is a Locals window. In that window, its will show the current value of the sql variable. If you can't read the whole thing thing, then add a line:

    Debug.Print sql

    before the highlighted line and it will display the value of sql in the Immediate window.
    Ok so I have Debug.Print sql and this is what I was given:

    SELECT tblMain.ProjectCode, tblMain.EventDate, tblMain.Status, tblMain.OrganizationName, tblMain.Province, tblMain.ProjectType, tblFiscalBudget.FiscalYear, tblFiscalBudget.Budget, tblBudgetItems.BudgetItems, tblCategory.PolicyArea, tblCategory.Priority, tblCategory.ScheduleAExceptions
    FROM ((tblMain LEFT JOIN tblFiscalBudget ON tblMain.ProjectCode = tblFiscalBudget.ProjectCode) LEFT JOIN tblBudgetItems ON tblFiscalBudget.ProjectCode = tblBudgetItems.ProjectCode) LEFT JOIN tblCategory ON tblBudgetItems.ProjectCode = tblCategory.ProjectCode WHERE (FiscalYear = '11/12') ORDER BY tblMain.ProjectCode;
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #10

    Jun 16, 2009, 08:06 AM
    Bingo! There it is. The code you originally posted didn't show any WHERE clauses. There must be addditional code that added the WHERE clause. So, do you see it now?
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #11

    Jun 16, 2009, 11:14 AM
    Quote Originally Posted by ScottGem View Post
    Bingo! There it is. The code you originally posted didn't show any WHERE clauses. There must be addditional code that added the WHERE clause. So, do you see it now?
    Ha! I see!
    So I shoud add this:

    WHERE (FiscalYear = '11/12') ORDER BY tblMain.ProjectCode;

    to the original code that I posted?
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #12

    Jun 16, 2009, 11:30 AM

    Somewhere in your code its adding a WHERE clause to the sql variable. You need to find where that's happening. Then you need to fully qualify the FiscalYear field by indicating the table its being drawn from.

    What I don't know is where that will be.

    Looking through the code you previously posted, it appears you are always pulling FiscalYear from tblFiscalBudget. So would change the WHERE clause to:
    WHERE (tblFiscalBudget.FiscalYear =

    I would suspect, you are concatening in a value on the other side of the equals sign.
    mcleyn's Avatar
    mcleyn Posts: 48, Reputation: 1
    Junior Member
     
    #13

    Jun 16, 2009, 12:44 PM
    Quote Originally Posted by ScottGem View Post
    Somewhere in your code its adding a WHERE clause to the sql variable. You need to find where that's happening. Then you need to fully qualify the FiscalYear field by indicating the table its being drawn from.

    What I don't know is where that will be.

    Looking through the code you previously posted, it appears you are always pulling FiscalYear from tblFiscalBudget. So would change the WHERE clause to:
    WHERE (tblFiscalBudget.FiscalYear =

    I would suspect, you are concatening in a value on the other side of the equals sign.
    This is the only WHERE clause in all my code:

    sql = sql & "WHERE (" & Me.Filter & ") ORDER BY tblMain.ProjectCode;"

    So should I add the WHERE (tblFiscalBudget.FiscalYear.. to this?

    Yes I am concatening a value on the other side '11/12' stands for the years 2011 and 2012.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #14

    Jun 16, 2009, 12:57 PM

    Ahh I see. This presents a problem. I thionk what you are going to need to do is test the left side of Me.Filter and add the table qualifier accordingly.

    For example:

    strField = Left(Me.Filter,Instr(1,Me.Filter,"=")-2)

    If strField = "[FiscalYear]" Then
    sql = sql & "WHERE (tblFiscalBudgetYear]." & Me.Filter & ") ORDER BY tblMain.ProjectCode;"
    End If

    You ma need other possibilites if you can use different filters.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Vb 6.3 run time error [ 1 Answers ]

I need some help here. I am writing applications for my company using Excel 2003 and Visual Basic 6.3. The applications I have written before we got Windows XP used Excel and Visual Basic 6.0. To call up the Input form I have used the following code: Sub auto_open() UserForm1.Show End Sub ...

Error on my creditied time [ 6 Answers ]

Hi again! Last Sept. I was arrested in NY and waived extradition to NJ on day one. I arrived in NJ 15 days later and after a total of 78 days, was given 'time served & 1 yr. probation'. On my paperwork, I was given credit for only the time I spent in NJ: 68 days. This seems to be an error in how...

Run-time error when I try to print from AOL [ 2 Answers ]

Whenever I try to print a web page from Aol, I get a run-time error. AOL could not help me, none of their suggestions worked. Resetting Windows Explorer to ignore script errors did not work. Any suggestions?

Run time error [ 4 Answers ]

Hi, I get an error saying "RUN TIME ERROR 0450034323 " and if I click "OK' it disappears and the same error comes after some time , may I know what's the reason for this error. But I feel it doesn't affect any application.:eek:


View more questions Search