Eigendlich einfache Abfrage funktioniert nicht (SQL-Abfrage)

  • Access

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von Mono.

    Eigendlich einfache Abfrage funktioniert nicht (SQL-Abfrage)

    Ich habe ein Hauptformular die als Datenquelle eine Tabelle vom SQL Server hat. Im Detailbereich habe ich lauter Textboxen die als Steuerelementeinheit Spalten der Tabelle haben(ID, Name und sowas).

    Ich will für den Anfang nur ein Suchhfeld und einen Button haben mit dem man die ID suchen kann und die anderen Felder zu der ID angezeigt werden.

    Visual Basic-Quellcode

    1. Dim strSQL As String
    2. If Not IsNull(txtID) Then
    3. strSQL = "select dbo_T_Adresse " & _
    4. "from dbo_T_Adresse As T1 " & _
    5. " WHERE T1.dbo_T_Adresse.ID = '" & Me.txtID & "' "
    6. Forms!FRM_ADRESSE_HPTFRM.filter = strSQL
    7. Forms!FRM_ADRESSE_HPTFRM.FilterOn = True
    8. DoCmd.Close acForm, "FRM_Schnellsuche"
    9. Else: DoCmd.Close acForm, "FRM_Schnellsuche" 'Bei Suche nach nichts wird abgebrochen
    10. End If


    Ach ja, hier benutze ich eine zweite Form für die Suche, mir wäre es aber ersteinmal lieber, wenn das auf einer Form funktioniert.
    "WHERE T1.dbo_t_Adresse.ID" müsste das nicht "WHERE T1.ID" heißen? Du hast T1 doch als dbo_t_Adresse definiert.
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Was ist "SELECT dbo_T_Adresse" müsste das nicht "SELECT *" oder "SELECT ColumnName" heißen?
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Was möchstes du denn raussuchen?
    dbo_T_Adresse scheint deine Tabelle zu sein.

    Du solltest dir mal diese Seite ansehen W3Schools
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Hab Nochmal was anderes geschrieben

    Visual Basic-Quellcode

    1. Dim strSQL As String
    2. If Not IsNull(Text11) Then
    3. strSQL = "select dbo_T_Adresse.ID " & _
    4. "from dbo_T_Adresse " & _
    5. " WHERE dbo_T_Adresse.ID = '" & Me.Text11 & "' "
    6. Me!maiktest.Form.filter = strSQL
    7. Me!maiktest.Form.FilterOn = True
    8. Else
    9. Me!maiktest.Form.filter = ""
    10. ' Forms!FRM_ADRESSE_HPTFRM.filter = strSQL
    11. ' Forms!FRM_ADRESSE_HPTFRM.FilterOn = True
    OK und? Funktioniert es?
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    So funktioniert der Filter auch nicht. Weise das der RecordSource zu.
    Der Filter wäre zB bei einer Recordsource von "dbo_T_Adresse"
    ID = 2

    Verwende RecordSource für die Selectabfrage
    Das ist meine Signatur und sie wird wunderbar sein!
    ok das funktioniert, danke

    Visual Basic-Quellcode

    1. strSQL = "SELECT * FROM dbo_T_Adresse WHERE ((dbo_T_Adresse.ID)=FORMS!maiktest!Text11)"
    2. Me.RecordSource = strSQL


    der nächste Schritt wäre Formübergreifend

    FORMS!FORMULARNAME!FELDNAME =….

    funktioniert nicht geht das vielleicht mit einer globalen Variable?


    UPDATE: ich nehme den zweiten Teil zurück ich habe nur ein Ausrufezeichen vergessen

    Danke für die Hilfe Schamash und Mono
    Es würde gehen wenn du =Forms!formname!controlname verwendest als Datasource zB verwendest (Das = ist wichtig).
    Ich würde dies aber so oft es geht vermeiden, es sei denn es ist eine subform oder ein report der aus der form heraus geöffnet wird.
    Das ist meine Signatur und sie wird wunderbar sein!