Results 1 to 5 of 5
  1. #1
    Tism-RT is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    3

    Error with double AND statement

    While running next script, I always get an error. I cannot find a solution. Someone?

    Option Compare Database

    Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)
    Me.txtContactPersoon = NaamContactPersoon
    End Sub

    Private Sub Report_Open(Cancel As Integer)
    Dim rstContactPersoon As New ADODB.Recordset

    rstContactPersoon.Open "SELECT tbl_Stagebedrijven.Stb_ID, tblWerkpostFiches.WerkpostFicheId, tbl_Stagebedrijven.StB_Naam, tbl_Contacten.Cp_Familienaam, tbl_Contacten.Cp_Voornaam, tbl_Contacten.Hcp " _
    & "FROM (tbl_Stagebedrijven INNER JOIN tblWerkpostFiches ON tbl_Stagebedrijven.Stb_ID = tblWerkpostFiches.StageBedrijfId) INNER JOIN tbl_Contacten ON tbl_Stagebedrijven.Stb_ID = tbl_Contacten.Stb_ID" _
    & "WHERE (((tbl_Stagebedrijven.Stb_ID)=" & [Forms]![frmWerkpostFisches]![txtStb_ID] & ") AND (( tblWerkpostFiches.WerkpostFicheId)=" & [Forms]![frmWerkpostFisches]![subFrmWerkpostFiche].[Form]![txtWerkpostFicheId] & ") AND ((tbl_Contacten.Hcp) = True));", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

    'rstContactPersoon.Open "SELECT tbl_Stagebedrijven.Stb_ID, tblWerkpostFiches.WerkpostFicheId, tbl_Stagebedrijven.StB_Naam, tbl_Contacten.Cp_Familienaam, tbl_Contacten.Cp_Voornaam " _
    ' & "FROM (tbl_Stagebedrijven INNER JOIN tblWerkpostFiches ON tbl_Stagebedrijven.Stb_ID = tblWerkpostFiches.StageBedrijfId) INNER JOIN tbl_Contacten ON tbl_Stagebedrijven.Stb_ID = tbl_Contacten.Stb_ID " _
    ' & "WHERE (((tbl_Stagebedrijven.Stb_ID)=" & [Forms]![frmWerkpostFisches]![txtStb_ID] & ") AND ((tblWerkpostFiches.WerkpostFicheId)=" & [Forms]![frmWerkpostFisches]![subFrmWerkpostFiche].[Form]![txtWerkpostFicheId] & "));", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

    NaamContactPersoon = rstContactPersoon(3) & " " & rstContactPersoon(4)



    End Sub

    Thanks

  2. #2
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    What is the error and where?

    I would also add Option Explicit to the top of your all your modules. It will highlight undeclared Variables, and typo's.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Tism-RT is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    3
    Quote Originally Posted by Minty View Post
    What is the error and where?

    I would also add Option Explicit to the top of your all your modules. It will highlight undeclared Variables, and typo's.
    Option Compare Database

    Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)
    Me.txtContactPersoon = NaamContactPersoon
    End Sub

    Private Sub Report_Open(Cancel As Integer)
    Dim rstContactPersoon As New ADODB.Recordset


    rstContactPersoon.Open "SELECT tbl_Stagebedrijven.Stb_ID, tblWerkpostFiches.WerkpostFicheId, tbl_Stagebedrijven.StB_Naam, tbl_Contacten.Cp_Familienaam, tbl_Contacten.Cp_Voornaam, tbl_Contacten.Hcp " _
    & "FROM (tbl_Stagebedrijven INNER JOIN tblWerkpostFiches ON tbl_Stagebedrijven.Stb_ID = tblWerkpostFiches.StageBedrijfId) INNER JOIN tbl_Contacten ON tbl_Stagebedrijven.Stb_ID = tbl_Contacten.Stb_ID" _
    & "WHERE (((tbl_Stagebedrijven.Stb_ID)=" & [Forms]![frmWerkpostFisches]![txtStb_ID] & ") AND (( tblWerkpostFiches.WerkpostFicheId)=" & [Forms]![frmWerkpostFisches]![subFrmWerkpostFiche].[Form]![txtWerkpostFicheId] & ") AND ((tbl_Contacten.Hcp) = True));", CurrentProject.Connection, adOpenKeyset, adLockOptimistic


    'rstContactPersoon.Open "SELECT tbl_Stagebedrijven.Stb_ID, tblWerkpostFiches.WerkpostFicheId, tbl_Stagebedrijven.StB_Naam, tbl_Contacten.Cp_Familienaam, tbl_Contacten.Cp_Voornaam " _
    ' & "FROM (tbl_Stagebedrijven INNER JOIN tblWerkpostFiches ON tbl_Stagebedrijven.Stb_ID = tblWerkpostFiches.StageBedrijfId) INNER JOIN tbl_Contacten ON tbl_Stagebedrijven.Stb_ID = tbl_Contacten.Stb_ID " _
    ' & "WHERE (((tbl_Stagebedrijven.Stb_ID)=" & [Forms]![frmWerkpostFisches]![txtStb_ID] & ") AND ((tblWerkpostFiches.WerkpostFicheId)=" & [Forms]![frmWerkpostFisches]![subFrmWerkpostFiche].[Form]![txtWerkpostFicheId] & "));", CurrentProject.Connection, adOpenKeyset, adLockOptimistic



    NaamContactPersoon = rstContactPersoon(3) & " " & rstContactPersoon(4)

    End Sub

  4. #4
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    There is a missing space at the end of the second line, the FROM clause.

    You would spot these type of error if you build the string first then you can debug it. Something like;

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)
    
    
        Me.txtContactPersoon = NaamContactPersoon
    
    
    End Sub
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Private Sub Report_Open(Cancel As Integer)
    
    
        Dim rstContactPersoon As New ADODB.Recordset
        Dim sSql             As String
    
    
        sSql = "SELECT tbl_Stagebedrijven.Stb_ID, tblWerkpostFiches.WerkpostFicheId, tbl_Stagebedrijven.StB_Naam, tbl_Contacten.Cp_Familienaam, tbl_Contacten.Cp_Voornaam, tbl_Contacten.Hcp "
        sSql = sSql & "FROM (tbl_Stagebedrijven INNER JOIN tblWerkpostFiches ON tbl_Stagebedrijven.Stb_ID = tblWerkpostFiches.StageBedrijfId) INNER JOIN tbl_Contacten ON tbl_Stagebedrijven.Stb_ID = tbl_Contacten.Stb_ID "
        sSql = sSql & "WHERE (((tbl_Stagebedrijven.Stb_ID)=" & [Forms]![frmWerkpostFisches]![txtStb_ID] & ") AND (( tblWerkpostFiches.WerkpostFicheId)=" & [Forms]![frmWerkpostFisches]![subFrmWerkpostFiche].[Form]![txtWerkpostFicheId] & ") AND ((tbl_Contacten.Hcp) = True));"
    
    
        Debug.Print sSql            'This will print out the sql statement in the immediate window to let you see any potential errors. Press ctrl + G to see the window.
        
        rstContactPersoon.Open sSql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    
        NaamContactPersoon = rstContactPersoon(3) & " " & rstContactPersoon(4)
    
    
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Tism-RT is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    3
    Quote Originally Posted by Minty View Post
    There is a missing space at the end of the second line, the FROM clause.

    You would spot these type of error if you build the string first then you can debug it. Something like;

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)
    
    
        Me.txtContactPersoon = NaamContactPersoon
    
    
    End Sub
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Private Sub Report_Open(Cancel As Integer)
    
    
        Dim rstContactPersoon As New ADODB.Recordset
        Dim sSql             As String
    
    
        sSql = "SELECT tbl_Stagebedrijven.Stb_ID, tblWerkpostFiches.WerkpostFicheId, tbl_Stagebedrijven.StB_Naam, tbl_Contacten.Cp_Familienaam, tbl_Contacten.Cp_Voornaam, tbl_Contacten.Hcp "
        sSql = sSql & "FROM (tbl_Stagebedrijven INNER JOIN tblWerkpostFiches ON tbl_Stagebedrijven.Stb_ID = tblWerkpostFiches.StageBedrijfId) INNER JOIN tbl_Contacten ON tbl_Stagebedrijven.Stb_ID = tbl_Contacten.Stb_ID "
        sSql = sSql & "WHERE (((tbl_Stagebedrijven.Stb_ID)=" & [Forms]![frmWerkpostFisches]![txtStb_ID] & ") AND (( tblWerkpostFiches.WerkpostFicheId)=" & [Forms]![frmWerkpostFisches]![subFrmWerkpostFiche].[Form]![txtWerkpostFicheId] & ") AND ((tbl_Contacten.Hcp) = True));"
    
    
        Debug.Print sSql            'This will print out the sql statement in the immediate window to let you see any potential errors. Press ctrl + G to see the window.
        
        rstContactPersoon.Open sSql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    
        NaamContactPersoon = rstContactPersoon(3) & " " & rstContactPersoon(4)
    
    
    End Sub

    Hi Minty,

    A thousand times thanks!! Works perfect! I just didn't see the missing space...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. SQL statement with double negative
    By aaslezak in forum Queries
    Replies: 2
    Last Post: 06-02-2015, 09:42 AM
  2. Single and double quotes in a INSERT statement
    By dccjr in forum Programming
    Replies: 16
    Last Post: 03-14-2013, 09:50 PM
  3. Send email error and double up address
    By burrina in forum Forms
    Replies: 6
    Last Post: 01-21-2013, 03:49 PM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. OpenReport Command with Double Check Where Statement
    By Robert M in forum Programming
    Replies: 3
    Last Post: 09-17-2009, 04:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums