Results 1 to 2 of 2
  1. #1
    ohi is offline Novice
    Windows XP Access 2002
    Join Date
    Nov 2009
    Posts
    5

    Module that takes 2 fields from a query and merges them into one

    I apologize for the above, this project is in 2007 not 2002

    Hi, I have the following code I'm using to merge 2 current fields in a new table, along with other data.

    It works as it should when there are multiple records in the one field, however, when there is only one record, it skips it. I cannot figure out what's wrong, any assistance would be great. I did not write this code myself, I had help.



    Code:
    Private Function usethis()
    Dim rstmain As Recordset
    Dim rsttbl As Recordset
    Dim strfld As String
    Dim strcasenbr As String
    
    Set rstmain = CurrentDb.OpenRecordset("ICAC Report")
    Set rsttbl = CurrentDb.OpenRecordset("copy of ICAC Export")
    
    rstmain.MoveLast
    rstmain.MoveFirst
    strfld = ""
    strcasenbr = rstmain![Case Number]
    
    Do Until rstmain.EOF
    
    
        Do While strcasenbr = rstmain![Case Number]
            strfld = strfld & rstmain![Type] & vbCrLf
            rstmain.MoveNext
            If rstmain.EOF Then
            rstmain.MovePrevious
            GoTo skip
            End If
        Loop
    skip:
    rstmain.MovePrevious
    rsttbl.AddNew
    rsttbl!IntakeDate = rstmain![Intake Date]
    rsttbl!DateRecent = rstmain![Date of Recent Activity]
    rsttbl!TypeReceived = rstmain![Type Received]
    rsttbl!NameandItems = rstmain![Subject] & vbcrrlf & strfld
    rsttbl!CaseType = rstmain![Secondary Case Type]
    rsttbl!CaseNumber = rstmain![Case Number]
    rsttbl!Comments = rstmain![Comments]
    rsttbl.Update
    rstmain.MoveNext
    rstmain.MoveNext
    If rstmain.EOF Then GoTo iamdone
    strcasenbr = rstmain![Case Number]
    strfld = ""
    Loop
    iamdone:
    
    End Function

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    wouldn't use that method at all.

    set up a query - - then use a calculated field that gives you what you want.....

    then make an Update query using the first query as its source...

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

Similar Threads

  1. How do I use a MODULE in a Cross-Tab Query?
    By timo1999 in forum Modules
    Replies: 2
    Last Post: 12-13-2014, 04:51 PM
  2. Calculating Interest with a Module
    By jgelpi16 in forum Modules
    Replies: 2
    Last Post: 09-30-2012, 05:08 AM
  3. Query Design View Takes a Long Time to Open
    By jackthedog in forum Queries
    Replies: 0
    Last Post: 12-22-2009, 03:27 PM
  4. Module not found
    By nooby in forum Modules
    Replies: 1
    Last Post: 12-02-2009, 02:20 PM
  5. Replies: 9
    Last Post: 10-09-2009, 08:15 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