SQL Runtime Error 3075

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

Not sure if the information I am giving is enough for you to help me.

This is a code I try to run but I am getting an runtime Error 3075 missing element or in query it is in the WHERE Clause..

Code:
Private Sub btnTest_Click()
    Dim strSQL As String
    Dim strSQLTeil As String

    Dim Dateiname As String


    Select Case Me!fraStatus
        Case 1
            strSQLTeil = "tblStatus.staID=1"
        Case 2
            strSQLTeil = "tblStatus.staID=2"
        Case Else
            strSQLTeil = "tblStatus.staID>0"
     End Select
     
strSQL = "SELECT tblObjekte.objID, IIf([kunFirma] Is Null,[kunVorname] & "" "" & [kunNachname],[kunFirma]) AS Kontakt, tblObjekte.objAdresse, tblObjekte.objOrt, tblStatus.staID " & _
"FROM tblStatus INNER JOIN (tblKunden INNER JOIN tblObjekte ON tblKunden.kunID = tblObjekte.objKunIDRef) ON tblStatus.staID = tblObjekte.objStatIDRef " & _
"WHERE [COLOR=#ff0000](((tblObjekte.objID)=[Formulare]![frmObjektAuswahl]![cboTest]) AND " & strSQLTeil[/COLOR]
    
    CurrentDb.QueryDefs("qryObjektTest").SQL = strSQL
    
         DoCmd.OpenQuery "qryObjektTest"
End Sub

does anyone of you guys know where I this is wrong?

Thanks
 
Hi James_lankford,
thank you for your mail!
I got it working now! But still got an issue..

Code:
Private Sub btnUpdate_Click()
    Dim strSQL As String
    Dim strSQLTeil As String
    Dim Dateiname As String
    
        Select Case Me!fraStatus
            Case 1
                strSQLTeil = "tblStatus.staID=3"
            Case 2
                strSQLTeil = "tblStatus.staID=2"
            Case Else
                strSQLTeil = "tblStatus.staID>0"
        End Select
    
        strSQL = strSQL & " SELECT tblObjekte.objID, IIf([kunFirma] Is Null,[kunVorname] & "" "" & [kunNachname],[kunFirma]) AS Kontakt, tblObjekte.objAdresse, tblObjekte.objOrt, tblStatus.staBezeichnung,tblStatus.staID  "
        strSQL = strSQL & " FROM tblStatus INNER JOIN (tblKunden INNER JOIN tblObjekte ON tblKunden.kunID = tblObjekte.objKunIDRef) ON tblStatus.staID = tblObjekte.objStatIDRef "
        strSQL = strSQL & " WHERE tblObjekte.objOrt=[Formulare]![frmObjektAuswahl]![cboObjOrte] AND " & strSQLTeil
    
        CurrentDb.QueryDefs("qryObjektAuswahl").SQL = strSQL
        
        Me!lstObjekte.Requery
        DoCmd.OpenQuery "qryObjektAuswahl"
End Sub

How can I now update the listbox "lstObjekte" ?
I got is sorted that the qryObjektAuswahl gets displayed and updated the listbox rowsource in the form for that query .. I guess there is the problem or?

I guess I supose to leave it blank or? Sorry am confused :)

Thanks
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How are you populating the listbox?
 
Upvote 0
Hi Norie,

On Load event
Code:
Private Sub Form_Load()
    Forms!frmObjektAuswahl!cboObjOrte.RowSourceType = "Table/Query"
    Forms!frmObjektAuswahl![cboObjOrte].RowSource = "qryObjektOrteDynamisch"
    
    
    Me!cboObjOrte = Me!cboObjOrte.ItemData(0)
    Me!lstObjekte.RowSource = "qryObjektAuswahl"
    Me!lstObjekte.Requery
End Sub
 
Upvote 0
Hi Norie,

as soon I wrote this I got it sorted!
It works now!!
However there is one thing I like to change.. I don't like to press a button I like to have it updated as soon I change the frame.. so in the after update event of the fraStatus or?
Or is it better the change event? .)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,645
Messages
6,120,711
Members
448,984
Latest member
foxpro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top