Results 1 to 7 of 7
  1. #1
    Slot is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    3

    Make a continuous list from a field within a table

    Apologies for asking here but I've trawled the web for the last 2 hours and can't find what I'm looking for.

    Plus go easy on me I'm a novice when it comes to access.

    I have a table - lets call it TableEmployee

    Within that table I have a number of fields, for example

    Name
    Payroll
    Department

    In total ther are over 300 employees within the table with all three fields populated for each.

    I then have a Query - again lets call it QryFilter. This enables me to search and filter out only those that are from a particular department. IE I will search on workshop and it pulls back 100 records.

    Now what I would like to do is from the query is produce a string, either in another table or within a text box, where all the payroll numbers from the results of the search are combined into a continuous string with a coma between each. (don't require any of the other fileds, just payroll numbers)

    IE the end result I am looking for something like this

    AG1785,AD6835,GH6895,JK8976,FG6795 and so on for the 100 odd records that it will pull back



    (just to put it into context I then need to copy and paste the string produced and drop into into some other software)

    Again, apologies if this has been covered a 1,000 times before but I'm struggling

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    You may be better off doing this in VBA. Here is an example. I have not verified this for syntax, but should help out.

    What this will do is take each Payroll Number from your Query and dump it into a text box on a form. I would put this code in a click event of a button.

    Code:
    Dim db as Database
    Dim rs as Recordset
    Dim vPayrollNum as String
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("QryFilter", dbOpenDynaset)
    rs.MoveLast
    rs.MoveFirst
    
    Do While Not rs.EOF
         vPayrollNum = vPayrollNum & ", " & rs("Payroll")
         rs.MoveNext
    Loop
    
    txtResults.Value = vPayrollNum '--------> txtResults is the name I gave the text box, it can be whatever you want
    rs.Close
    Let me know if you have any questions.

  3. #3
    Slot is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    3
    Many thanks. Potentially it looks like its working.

    I say potentially as I get a run time error - 3163 "The field is too small to accept the amount of data you attempted to add. Try inserying or pasting less data"

    In total the 'list' I'm attemptoing to pull over should be 80 'payroll's in number, each payroll being 10 or 11 digits.

    I tried all the dumb things us novices try. Increasing the box size, hunting through properties for something which limits the numbers etc.

    I did filter out alot of the results and retested it with just 5 records and they popluated the text box perfectly so it would appear that size does matter. Any ideas - managed to find something which said there was a 100 character limit on it but not sure if that sounds right

  4. #4
    Slot is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    3
    Forget it, just redid the text box and works perfectly now - Thanks for helping me out, greatly appreciated, owe you a beer

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Didn't realize you were working with such a large population. I apologize. Let's try another method. Create a table with a field in it and set the field to Memo instead of Text. Then run the below code instead of the txtRests.Value = vPayrollNum.

    Code:
    Dim mySQL as string
    
    mySQL = "INSERT INTO tableName (FieldToInsertValuesTo) VALUES (" & vPayrollNum & ");"
    CurrentDb.Execute mySQL, dbFailOnError
    IF your payroll numbers are formatted as text instead of number you'll need to use the below statement:
    Code:
    mySQL = "INSERT INTO tableName (FieldToInsertValuesTo) VALUES ('" & vPayrollNum & "');"
    Notice the ' in the VALUES portion before and after the vPayrollNum portion. This designates the value as numeric where as the first one with the absence of the ' declares the value as a number.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    FYI, there are two other options are available.

    1) Loop thru the recordset, writing to a text file. (I use this a lot)

    2) Use the "TransferText Action". You can set up an export specification to transfer the data to a text file.

  7. #7
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    It seems that this is another form of regex exercise in access query result.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-29-2010, 08:01 AM
  2. Creating Yes/No Field Using Make Table
    By orcinus in forum Queries
    Replies: 6
    Last Post: 08-19-2010, 11:09 PM
  3. Field changes in Make table query
    By asherbear in forum Queries
    Replies: 9
    Last Post: 05-29-2010, 01:35 PM
  4. Replies: 2
    Last Post: 04-20-2010, 12:47 PM
  5. Replies: 1
    Last Post: 12-09-2005, 09:27 PM

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