Results 1 to 7 of 7
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    ConCat question

    HI all,
    I cannot figure out how to concat this and have tried so many ways?
    I marked it in red below



    Code:
    Private Sub CmdReport_Click()
    On Error Resume Next
    
    
    Dim varItem As Variant
    Dim strDoc As String
    
    
    If IsNull(Me.LstAccountReport.Column(0)) Then
        MsgBox "You must select a Report from Reprot List!"
        Exit Sub
    End If
    
    
       With Me.LstAccountReport
            For Each varItem In .ItemsSelected
               strDoc = .Column(1, varItem) 'assumes list box has two columns, the first one holding the reportID is the bound one and hidden
        Next
        End With
    If Not IsNull(Me.LstAccountType.Column(0)) And (Me.grpFilterOptions = 2) Then
        DoCmd.OpenReport strDoc, acViewPreview, , "[AccountTypeID] in(" & getLBX(Me.LstAccountType) & ")"
        
    ElseIf Not IsNull(Me.LstAccountType.Column(0)) And (Me.grpFilterOptions = 1) Then
        DoCmd.OpenReport strDoc, acViewPreview, , "[AccountTypeID] in(" & getLBX(Me.LstAccountType) & ") AND" & Forms![frmAccount].[sfrmAccount].Form.txtReportFilter, , "frmAccountReport"
        
    ElseIf Forms!frmAccount.sfrmAccount.Form.chkSingle = True Then
           If Me.grpFilterOptions = 2 Then
                DoCmd.OpenReport strDoc, acViewPreview, , "AccountID=" & Forms!frmAccount!AccountID, , "frmAccountReport"
        Else
            DoCmd.OpenReport strDoc, acViewPreview, , "AccountID=" & Forms!frmAccount!AccountID & Forms![frmAccount].[sfrmAccount].Form.txtReportFilter, , "frmAccountReport"
        End If
        
    Else
        
        If Me.grpFilterOptions = 2 Then
            DoCmd.OpenReport strDoc, acViewPreview
        Else
            DoCmd.OpenReport strDoc, acViewPreview, , Forms![frmAccount].[sfrmAccount].Form.txtReportFilter, acNormal, "frmAccountReport"
        End If
    
    
    End If
    Thank you
    Dave

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I don't get the question. Concatenate what? It looks to me like that should compile ok. Looks ok as long as the form values are not text.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    It does compile but creates an syntax error when run!
    We had a similar problem with the code above it and he corrected it by adding this & ") AND" & so thinking there must be a way of concatenating like that I am missing
    "[AccountTypeID] in(" & getLBX(Me.LstAccountType) & ") AND" & Forms![frmAccount].[sfrmAccount].Form.txtReportFilter

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    How about replacing the references with actual values and type it out as a sentence and not code? Or is this (note the blue and red)
    "AccountID=" & Forms!frmAccount!AccountID & Forms![frmAccount].[sfrmAccount].Form.txtReportFilter, , "frmAccountReport"
    supposed to become like this
    "AccountID=" & 59, , "frmAccountReport"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Fixed it
    Wow, took all morning to do this!
    DoCmd.OpenReport strDoc, acViewPreview, , "AccountID=" & Forms!frmAccount!AccountID & "AND" & Forms![frmAccount].[sfrmAccount].Form.txtReportFilter, , "frmAccountReport"

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Kinda surprised that works. I would have thought it had to be " AND "
    So your criteria is that AccountID = 5 AND 9 ? Because that's what you're saying.
    Last edited by Micron; 04-22-2023 at 09:25 AM. Reason: added comment
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by d9pierce1 View Post
    Fixed it
    Wow, took all morning to do this!
    DoCmd.OpenReport strDoc, acViewPreview, , "AccountID=" & Forms!frmAccount!AccountID & "AND" & Forms![frmAccount].[sfrmAccount].Form.txtReportFilter, , "frmAccountReport"
    Cannot see that working either?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Concat BuildStr
    By shank in forum Modules
    Replies: 8
    Last Post: 10-06-2020, 12:59 PM
  2. Concat textbox name with string
    By dwif in forum Access
    Replies: 2
    Last Post: 06-08-2013, 02:31 PM
  3. Last Name, First Name Concat Field
    By brianmcleer in forum Access
    Replies: 2
    Last Post: 06-05-2013, 12:18 PM
  4. Group concat
    By iostream in forum Queries
    Replies: 1
    Last Post: 02-23-2011, 12:29 PM
  5. concat problem
    By leahcim_32 in forum Access
    Replies: 1
    Last Post: 08-28-2009, 05:31 AM

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