Results 1 to 9 of 9
  1. #1
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212

    Code has stopped working? Could anyone suggest why? Thankyou

    This code has worked on any versions of Office, but not on 2007 and up.



    It depends on CombineNames Module and CombineAddresses Module, but these are correctly identifying the fields.
    Code:
    Function CombineNamesAddresses$(FormName$, BaseName$)
    '
    'Combines upto 4 names and addresses with BaseName on Form$.
    'Each address is combined to a single line.
    'Names without an address are attached to the previous name.
    'Duplicate addresses (for sequential entries) are treated as name only above.
    '
    'The name consists of these fields (all prefixed with BaseName$):
    'Prefix FName Initials LName Suffix
    '
    'Likewise the address consists of:
    'Add City State Zip
    ''Add' is converted to a single line.
      Dim Name1, Name2, Name3, Name4 As Variant
      Dim Addr1, Addr2, Addr3, Addr4 As Variant
      Dim Full$
    
      'Build all the names
      Name1 = CombineName(FormName$, BaseName$ + "1")
      Name2 = CombineName(FormName$, BaseName$ + "2")
      Name3 = CombineName(FormName$, BaseName$ + "3")
      Name4 = CombineName(FormName$, BaseName$ + "4")
      '...and the addresses
      Addr1 = CombineAddress(FormName$, BaseName$ + "1")
      Addr2 = CombineAddress(FormName$, BaseName$ + "2")
      Addr3 = CombineAddress(FormName$, BaseName$ + "3")
      Addr4 = CombineAddress(FormName$, BaseName$ + "4")
      'Pad out blank addresses
      If IsNull(Addr1) Then Addr1 = ""
      If IsNull(Addr2) Then Addr2 = Addr1
      If IsNull(Addr3) Then Addr3 = Addr2
      If IsNull(Addr4) Then Addr4 = Addr3
      'Combine names with the same address
      If Not (IsNull(Name1) Or IsNull(Name2) Or IsNull(Addr1)) Then
        If (Addr2 = Addr1) Then 'Second same as first
          Name1 = Name1 + " & " + Name2
          Name2 = Null
        End If
      End If
      If Not (IsNull(Name3) Or IsNull(Name4) Or IsNull(Addr3)) Then
        If (Addr4 = Addr3) Then
          Name3 = Name3 + " & " + Name4
          Name4 = Null
        End If
      End If
      Full$ = ""
      If Not (IsNull(Name1)) Then Full$ = Name1 + ", " + Addr1
      If Not (IsNull(Name2)) Then
        If Full$ <> "" Then Full$ = Full$ + Chr(13) + Chr(10)
        Full$ = Full$ + Name2 + ", " + Addr2
      End If
      If Not (IsNull(Name3)) Then
        If Full$ <> "" Then Full$ = Full$ + Chr(13) + Chr(10)
        Full$ = Full$ + Name3 + ", " + Addr3
      End If
      If Not (IsNull(Name4)) Then
        If Full$ <> "" Then Full$ = Full$ + Chr(13) + Chr(10)
        Full$ = Full$ + Name4 + ", " + Addr4
      End If
      CombineNamesAddresses$ = Full$
    End Function
    Last edited by Abacus1234; 06-12-2015 at 11:43 AM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    1. You coulda showed us WHERE the error is. Or what.
    2. dont use $
    3. indent
    4. Take care of your null problem at the start by adding an empty set...

    Name1 = CombineName(FormName$, BaseName$ + "1") & ""
    Name2 = CombineName(FormName$, BaseName$ + "2")& ""
    Name3 = CombineName(FormName$, BaseName$ + "3")& ""
    Name4 = CombineName(FormName$, BaseName$ + "4")& ""
    '...and the addresses
    Addr1 = CombineAddress(FormName$, BaseName$ + "1")& ""
    Addr2 = CombineAddress(FormName$, BaseName$ + "2")& ""
    Addr3 = CombineAddress(FormName$, BaseName$ + "3")& ""
    Addr4 = CombineAddress(FormName$, BaseName$ + "4")& ""

    CombineName and CombineAddress functions arent shown.

    I'll continue looking...

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What does 'not working' mean - error message, wrong results, nothing happens?

    Have you step debugged?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Apologies for omissions.

    The error originally was that nothing appeared.

    When I took off the $ from FormName and BaseNameEX

    I got #Name?

    I have included the other two modules.

    Is $ an old construct? Is it appropriate in some places? Thanks

    Function CombineName(FormName$, BaseNameEx$)
    'Combine the name fields on FormName$.BaseNameEx$ as defined for
    'CombineNamesAddresss
    Dim TempName$
    ' If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "Prefix"))) Then
    ' TempName$ = Forms(FormName$)(BaseNameEx$ + "Prefix")
    ' Else
    TempName$ = ""
    ' End If

    If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "FName"))) Then
    If TempName$ <> "" Then TempName$ = TempName$ + " "
    TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "FName")
    End If
    ' If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "Initials"))) Then
    ' If TempName$ <> "" Then TempName$ = TempName$ + " "
    ' TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "Initials")
    ' End If
    If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "LName"))) Then
    If TempName$ <> "" Then TempName$ = TempName$ + " "
    TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "LName")
    End If
    'If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "Suffix"))) Then
    ' If TempName$ <> "" Then TempName$ = TempName$ + " "
    ' TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "Suffix")
    'End If
    If TempName$ = "" Then
    CombineName = Null
    Else
    CombineName = TempName$
    End If
    End Function
    Function CombineAddress(FormName$, BaseNameEx$)
    'Combine the address fields on FormName$.BaseNameEx$ as defined for
    'CombineNamesAddresss
    'Add City State Zip
    ''Add' is converted to a single line.

    Dim TempName$
    If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "Add"))) Then
    TempName$ = StripCRLF(Forms(FormName$)(BaseNameEx$ + "Add"))
    Else
    TempName$ = ""
    End If

    If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "City"))) Then
    If TempName$ <> "" Then TempName$ = TempName$ + ", "
    TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "City")
    End If
    If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "StateA"))) Then
    If TempName$ <> "" Then TempName$ = TempName$ + ", "
    TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "StateA")
    End If
    If Not (IsNull(Forms(FormName$)(BaseNameEx$ + "Zip"))) Then
    If TempName$ <> "" Then TempName$ = TempName$ + " "
    TempName$ = TempName$ + Forms(FormName$)(BaseNameEx$ + "Zip")
    End If
    If TempName$ = "" Then
    CombineAddress = Null
    Else
    CombineAddress = TempName$
    End If
    End Function

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Post code with CODE tags and indentation will be retained to make more readable.

    I have never used $ for anything.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I have used code with it before. I have not and do not build code using identifiers like that. I have not been coding long enough. But this is how I understand identifiers are used.

    Code:
    Dim strThis$
    Dim intNumber%
    strThis = "Food"
    intNumber = 5
    MsgBox strThis & " " & intNumber

    https://msdn.microsoft.com/en-us/library/s9cz43ek.aspx


    So I would have to spend some time to understand the code posted here. The thing that jumps out the most as unfamiliar are the namespaces and the syntax for the fully qualified names. Maybe I am not looking at correctly ...

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the early days of the IBM XT and the Apple II, BASIC, GW BASIC, Integer BASIC (Apple) & Floating Point BASIC(Apple), special characters were used to declare a variable type. "DIM" could be used, but it took more (valuable) memory so the "DIM" statement was largely not used.

    The variable types were:
    Code:
    Character Type of Variable
    
    $ String variable
    % Integer variable
    ! Single-precision variable
    # Double-precision variable
    
    
    The following are sample variable names for each type:
    
    Variable Type                   Sample Name
    
    String variable                  N$
    Integer variable                 LIMIT%
    Single-precision variable        MINIMUM!
    Double-precision variable        Pl#
    NOTE: While you can still use the special characters to define variables (for backward compatibility), these declarations have been deprecated.


    If you do not use "Option Explicit" at the top of every module, you can end up writing spaghetti code! Misspelling a variable will create a new variable and sometimes be very hard to find the error.
    "Option Explicit" REQUIRES variables to be declared before use.


    --------------------------------------------------------------
    Dim Name1, Name2, Name3, Name4 As Variant
    Dim Addr1, Addr2, Addr3, Addr4 As Variant
    Declaring variables like this does not result in what you might think (unlike some other programming languages).
    Lets say that the lines are changed to
    Code:
      Dim Name1, Name2, Name3, Name4 As String
      Dim Addr1, Addr2, Addr3, Addr4 As Integer
    The "Name" variables 1 -3 would be declared as type Variant and "Name4" would be declared as type string.
    The "Addr" variables 1 -3 would be declared as type Variant and "Addr4" would be declared as type string.

    --------
    Better declarations:
    You could use:
    Variants
    Dim Name1, Name2, Name3, Name4
    Dim Name1 As Variant, Name2 As Variant, Name3 As Variant, Name4 As Variant

    Other types:
    Dim Name1 As String, Name2 As String, Name3 As String, Name4 As String
    Dim Amt1 As Integer, Amt2 As Integer, Amt3 As Integer, Amt4 As Integer


    I use:
    Dim Name1 As String
    Dim Name2 As String
    Dim Name3 As String
    Dim Name4 As String

    Dim Amt1 As Integer
    Dim Amt2 As Integer
    Dim Amt3 As Integer
    Dim Amt4 As Integer

    More lines, but easier for me to find variables.....

  8. #8
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Couple things to try?

    1) Try to complile the code, it might show you where the error(s) are.
    2) Try a step by step debug and see where the error is.

  9. #9
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Thanks everyone for some great suggestions. my database had real problems and I had to spend several days re-building, thus taking my attention away from this problem. It all seems to be working now, which is good and bad. Why did it not work and Why does it now work again. However, working is better than not working, so I will leave well alone, but keep your suggestions on record.

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

Similar Threads

  1. Replies: 11
    Last Post: 10-15-2014, 07:38 PM
  2. Subforms stopped working
    By Paul H in forum Forms
    Replies: 7
    Last Post: 06-17-2014, 09:50 AM
  3. URGENT - Code stopped working
    By RachelBedi in forum Forms
    Replies: 2
    Last Post: 10-26-2012, 10:31 PM
  4. Access has stopped working
    By phillb in forum Forms
    Replies: 9
    Last Post: 01-10-2012, 12:22 PM
  5. All Buttons Stopped Working and...
    By rhoridge in forum Programming
    Replies: 1
    Last Post: 12-02-2010, 11:25 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