INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Can I convert a SQL type concatenate function into VB code

Can I convert a SQL type concatenate function into VB code

(OP)
I have a project where I need to concatenate data (employee names) from a field in a table where the field for cost codes in the table match the field for costs codes an open form.  I have used the following sql in a query based on a module that PHV and MRemou helped me with years ago.

'This is the concatenate of the Employee Names and Hours per Cost Code
Concatenate("SELECT[Employees] &  ': ' & [TotalSTHrs] &   ', ' & [TotalOTHrs] &   ', ' & [TotalDTHrs] WHERE [TblTimeSheetsDailyLogEmployees].[WEID]='" & [TblTimeSheetsDailyLogNotes].[WEID] & "'", Chr(13) & Chr(10))

This is what I am trying to convert it to in the Event Procedure in the form:    

Dim strConcat As String 'build return string
    Set rstTblTimeSheetsDailyLogEmployees = CurrentDb.OpenRecordset("TblTimeSheetsDailyLogEmployees", dbOpenDynaset)
     With rstTblTimeSheetsDailyLogEmployees
        If Not .EOF Then
       .FindFirst "[WEID]='" & strWEIDCode & "'"
            Do While Not .EOF
            .MoveFirst
                strConcat = strConcat & _
                    ![Employees]
                .MoveNext
            Loop
        End If
        .Close
    End With

I want to use the strConcat in the following procedure:

Set rstTblTimeSheetsDailyLogNotes = CurrentDb.OpenRecordset("TblTimeSheetsDailyLogNotes", dbOpenDynaset)
        
With rstTblTimeSheetsDailyLogNotes
  .FindFirst "[WEID]='" & strWEIDCode & "'"
  If .NoMatch Then Exit Sub Else .Edit
  ![EmployeesPerCode] = strConcat
  .Update
  
  End With


Any help here would be greatly appreciated!

RE: Can I convert a SQL type concatenate function into VB code

I don't know which Concatenate() function you are using but I think you can try an update query like:

CODE

UPDATE tblTimeSheetsdailyLogNotes
SET EmployeesPerCode = Concatenate("SELECT [Employees] FROM tblTimeSheetsDailyLogEmployees WHERE [WEID]='" & [WEID] & "'", Chr(13) & Chr(10))
This uses the Concatenate() function from the FAQs and make some assumptions about your tables, fields, data, and desires.

Duane
Hook'D on Access
MS Access MVP

RE: Can I convert a SQL type concatenate function into VB code

(OP)
Duane,

I was using this in a make table query which was very slow.  The update query is much better.  

Thanks for your help.

Johnnycat

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close