Link to home
Start Free TrialLog in
Avatar of Dustin Stanley
Dustin Stanley

asked on

MS Access SQL Query Issue Not Right At All

This one is driving me INSANE!!!!! I have several different forms and they are all search forms where I can search for different things. Well out of nowhere today I am trying to create a new form just like the rest and it is not working at all. i have compacted and repaired the database but it is giving BIG problems.

In my Query SQL it will not save the SQL. Once I exit and go back in it is the same as before and it will not find the "ORDERID" I am looking for.

I have a List box and I have one table with two fields. Orders.OrderID and Orders.CustomerID


On click of the list box i have the code:
Private Sub SearchResult_Click()
On Error GoTo Errorhandler
MsgBox "OrderID is " & Me!SearchResult


    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmOrdersReview"

    stLinkCriteria = "[OrderID]=" & Me![SearchResult]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit Sub

Errorhandler:
Application.Echo True
 MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
   VBE.ActiveCodePane.CodeModule, vbCritical, "Error in SearchResult_Click"
End Sub

Open in new window


The message box returns the value i expect but then Access errors out and says :

---------------------------
Error in SearchResult_Click
---------------------------
Error 3079: The specified field '[OrderID]' could refer to more than one table listed in the FROM clause of your SQL statement. in Form_frmOrderHistorySearch
---------------------------
OK  
---------------------------


There is only one single table in the query so how is this even possible. I have been here with this issue for several hours.

SQL:
SELECT Orders.OrderID, Orders.CustomerID
FROM Orders
ORDER BY Orders.OrderID;

Open in new window



This is driving my NUTS! Like I said I have several of these forms and they are all basically the same. I don't get it.  I thank you for the help.
ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dustin Stanley
Dustin Stanley

ASKER

Thanks!