2016-07-18 7 views
0

Ich versuche in letzter Zeit etwas zu tun innerhalb des Zugriffs und habe ein Problem, das ich nicht ruhig stellen kann.Access 2003 - VBA/query Fehlermeldung

habe ich diesen Code:

Option Compare Database 
Option Explicit 


Private Sub cboLocation_AfterUpdate() 
    Me.cboServer.RowSource = " SELECT tbl2Server.ServerID, tbl2Server.ServerName FROM tbl2Server " & _ 
     " WHERE LocationName = " & Nz(Me.cboLocation) & _ 
     " ORDER BY ServerName" 
    Me.cboServer = Null 

    EnableControls 
    FilterInterfacesList 

End Sub 

Private Sub cboServer_AfterUpdate() 
    Me.cboInterface.RowSource = " SELECT tbl2Vlan.VlanID, tbl2Vlan.InterfaceName FROM tbl2Vlan " & _ 
     " WHERE LocationName = " & Nz(Me.cboLocation) & _ 
     " ORDER BY InterfaceName" 
    Me.cboInterface = Null 

    EnableControls 
    FilterInterfacesList 

End Sub 

Private Sub cboInterface_AfterUpdate() 
    EnableControls 
    FilterInterfacesList 

End Sub 

Private Sub FilterInterfacesList() 
    Dim strInterface As String 

    strInterface = "SELECT qryServerInterfaces.LocationName, qryServerInterfaces.ServerName, qryServerInterfaces.InterfaceName, qryServerInterfaces.VlanName, qryServerInterfaces.IPAddress, qryServerInterfaces.DefaultGatewayAddress FROM qryServerooInterfaces" 

    If Not IsNull(Me.cboInterface) Then 
     strInterface = strInterface & " WHERE InterfaceName = " & Me.cboInterface 
    ElseIf Not IsNull(Me.cboServer) Then 
     strInterface = strInterface & " WHERE ServerName = " & Me.cboServer 
    ElseIf Not IsNull(Me.cboLocation) Then 
     strInterface = strInterface & " WHERE LocationName = " & Me.cboLocation 
    End If 

    strInterface = strInterface & " ORDER BY qryServerInterfaces.LocationName;" 

    Me.lstInterfaces.RowSource = strInterface 

    Me.lstInterfaces.Requery 

End Sub 

Private Sub EnableControls() 

    If IsNull(Me.cboLocation) Then 
     Me.cboServer = Null 
    End If 

    If IsNull(Me.cboServer) Then 
     Me.cboInterface = Null 
    End If 

    Me.cboServer.Enabled = (Not IsNull(Me.cboLocation)) 
    Me.cboInterface.Enabled = (Not IsNull(Me.cboServer)) 

End Sub 

Private Sub Form_Load() 
    EnableControls 

End Sub 

und eine Abfrage, die wie folgt aussieht: My query

Jetzt. mein Problem, wenn ich Kriterien unter "Sache" oder wie "Sache" bin, ist Null meine Abfrage wird Informationen zeigen. Wenn ich nicht alles unter "null" setze, zeigt mir mein Formular (Bild unten) nichts in seiner Liste.

Jetzt, wenn ich "null" meine Kriterien mache - bekomme ich seltsame Nachricht, die mir sagt, dass ich einen Fehler oder etwas habe (Bild unten).

Weiß jemand, was los ist? Danke im Voraus! Ich bin für 2 Wochen schon mit ihm stecken: '(

My Form

Vielen Dank im Voraus für jede mögliche Hilfe

SQL-Code

SELECT  tbl1Location.LocationName, 
      tbl2Server.ServerName, 
      tbl2Vlan.InterfaceName, 
      tbl2Vlan.VlanName, 
      tbl3IP.IPAddress, 
      tbl2Vlan.DefaultGatewayAddress 
FROM  ((tbl1Location INNER JOIN tbl2Server ON tbl1Location.LocationID = tbl2Server.LocationName) 
          INNER JOIN tbl2Vlan ON tbl1Location.LocationID = tbl2Vlan.LocationName) 
          INNER JOIN tbl3IP ON (tbl2Server.ServerID = tbl3IP.ServerName) 
              AND (tbl2Vlan.VlanID = tbl3IP.InterfaceName) 
WHERE  (
      ((tbl1Location.LocationName)=[Forms]![frmInterfaces]![cboLocation]) AND 
      ((tbl2Server.ServerName)=[Forms]![frmInterfaces]![cboServer]) AND 
      ((tbl2Vlan.InterfaceName)=[Forms]![frmInterfaces]![cboInterface]) 
      ) OR 
      (
      ((tbl2Server.ServerName)=[Forms]![frmInterfaces]![cboServer]) AND 
      ((tbl2Vlan.InterfaceName)=[Forms]![frmInterfaces]![cboInterface]) AND 
      ((([tbl1Location].[LocationName]) Like [Forms]![frmInterfaces]![cboLocation]) Is Null) 
      ) OR 
      (
      ((tbl1Location.LocationName)=[Forms]![frmInterfaces]![cboLocation]) AND 
      ((tbl2Vlan.InterfaceName)=[Forms]![frmInterfaces]![cboInterface]) AND 
      ((([tbl2Server].[ServerName]) Like [Forms]![frmInterfaces]![cboServer]) Is Null) 
      ) OR 
      (
      ((tbl2Vlan.InterfaceName)=[Forms]![frmInterfaces]![cboInterface]) AND 
      ((([tbl1Location].[LocationName]) Like [Forms]![frmInterfaces]![cboLocation]) Is Null) AND 
      ((([tbl2Server].[ServerName]) Like [Forms]![frmInterfaces]![cboServer]) Is Null) 
      ) OR 
      (
      ((tbl1Location.LocationName)=[Forms]![frmInterfaces]![cboLocation]) AND 
      ((tbl2Server.ServerName)=[Forms]![frmInterfaces]![cboServer]) AND 
      ((([tbl2Vlan].[InterfaceName]) Like [Forms]![frmInterfaces]![cboInterface]) Is Null) 
      ) OR 
      (
      ((tbl2Server.ServerName)=[Forms]![frmInterfaces]![cboServer]) AND 
      ((([tbl1Location].[LocationName]) Like [Forms]![frmInterfaces]![cboLocation]) Is Null) AND 
      ((([tbl2Vlan].[InterfaceName]) Like [Forms]![frmInterfaces]![cboInterface]) Is Null) 
      ) OR 
      (
      ((tbl1Location.LocationName)=[Forms]![frmInterfaces]![cboLocation]) AND 
      ((([tbl2Server].[ServerName]) Like [Forms]![frmInterfaces]![cboServer]) Is Null) AND 
      ((([tbl2Vlan].[InterfaceName]) Like [Forms]![frmInterfaces]![cboInterface]) Is Null) 
      ) OR 
      (
      ((([tbl1Location].[LocationName]) Like [Forms]![frmInterfaces]![cboLocation]) Is Null) AND 
      ((([tbl2Server].[ServerName]) Like [Forms]![frmInterfaces]![cboServer]) Is Null) AND 
      ((([tbl2Vlan].[InterfaceName]) Like [Forms]![frmInterfaces]![cboInterface]) Is Null) 
      ) 
+0

[3]: http://i.stack.imgur.com/1cvyN.png - Die Fehlermeldung –

+0

Das ist eine seltsame Abfrage - keine seltsame Fehlermeldung. Wenn Sie SQL anzeigen können und Kopieren/Einfügen ein Text in Ihrer Frage ist, der mit {} Code-Tags umschlossen ist, wäre das einfacher zu sehen. Ich denke, es gibt wahrscheinlich einen Weg, einige dieser Verbindungen zu eliminieren - sie sehen fast kreisförmig aus. Sie haben möglicherweise einige Unterabfragen erstellt - dann beitreten sie in dieser Abfrage – dbmitch

+0

Ich habe es hinzugefügt, ging zur Abfrage und kopieren Sie einfach eingefügt alle sichtbaren Code, den ich gesehen habe ... –

Antwort

0

Für alle, die das gleiche Problem :

Ich habe es "repariert", indem ich meine alte Abfrage lösche und jede Änderung debugge, die ich an der neuen gemacht habe.

Ich habe auch gelernt, dass, wenn ich möchte, dass irgendein Wert in irgendeiner Liste ist, die Abfrage den Wert, den richtigen Schlüssel enthalten sollte und das ist es. Sie können verwalten, was Ihre Liste, die Sie danach in der VBA-Code zeigen wird:

Me.mylist.RawSource = 'SELECT firstValue.myQuery, secondValue.myQuery, thirdValue.myQuery VON myQuery'

Die Abfrage Notwendigkeit, Halten Sie sowohl Ihre Datenwerte als auch Ihre IDs.