Results 1 to 7 of 7
  1. #1
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101

    Compile error in Query Expression - Help

    I am currently rebuilding one of my databases from scratch due changes in procedures. I felt it would be better to build a new DB from scratch instead of trying to make my current DB fit the new procedures.
    With that said I have built my two main tables which have a 1 to 1 relationship. My last DB had about 75 fields and my new DB table would have been more so I broke it into the two tables.
    I am using the following formula in my query to combine the First and Last name fields but I get a compile error. This is the same formula which I just copied and pasted from my other DB and then changed the field names.

    Last First: IIf(IsNull([ContLastName]),IIf(IsNull([ContFirstName]),[ContCompanyCode],[ContFirstName]),IIf(IsNull([ContFirstName]),[ContLastName],[ContLastName] & ", " & [ContFirstName]))

    Here is a screenshot of the error.

    Click image for larger version. 

Name:	CompileError1.JPG 
Views:	8 
Size:	64.1 KB 
ID:	22552

    Can anyone explain why I am getting this error and how I can correct it?
    Thank you for your responses.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Can we assume if there is no last name there will not be a first name?

    IIf(IsNull([ContLastName]), [ContCompanyCode], [ContLastName] & ", " + [ContFirstName])

    Otherwise

    IIf(Not IsNull([ContLastName]), [ContLastName] & ", " + [ContFirstName], IIf(Not IsNull([ContFirstName]), [ContFirstName], [ContCompanyCode]))

    Any expression involving math operators and Null will return Null. The + is a very special operation character. It not only does number addition but also concatenates. So if you '+' text data and any field is Null, the expression will return Null.

    Regarding use of IsNull http://allenbrowne.com/QueryPerfIssue.html


    Best not to use spaces in naming convention. LastFirst would be better.
    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.

  3. #3
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101
    I tried without the space and get the same error. In my old database I have a space in the Name and it works fine.

    This is from my old DB: Employee Name: IIf(IsNull([LastName]),IIf(IsNull([FirstName]),[HiringAgency],[FirstName]),IIf(IsNull([FirstName]),[LastName],[FirstName] & " " & [LastName]))

    I wouldn't think the length of the field names in my new DB would cause the problem? I never use spaces in field names only underscores.
    There is a reason why I use this formula instead of just doing: Name: [Last]&", "&[First]. I use the field "Employee Name" in my combo box code and at the top of my form to display the name.

    This is the formula at the top of my form: =Nz([Employee Name],"Untitled")

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    I edited my previous post while you were reading. Might review again.

    I meant space in field name, fine in calculation.
    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.

  5. #5
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101
    The two formulas you provided in your reply work. They work in my old database. I tried the 2 formulas in my new database with the same result, compile error. So I tried them in my old database with the correct field names and they worked.
    I did a Compact and Repair on my new DB and I still get the same compile error. I also tried to see if there is an issue with any kind of form controls. I created a quick form and tried to add a command button and get the error in the screenshot.


    Click image for larger version. 

Name:	CompileError2.JPG 
Views:	8 
Size:	39.2 KB 
ID:	22553

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    That they work in one db tells me possible corruption in other db. Maybe corruption beyond repair.

    Are you using custom function AppLoadString in both dbs? How does this function relate to the expressions?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  7. #7
    vad77 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2013
    Location
    USA
    Posts
    101
    I figured it out, it was a module I had created for table audits. What happened was that the statement "Option Compare Database" was in the module twice. I deleted the first instance and the query worked.
    Thanks for helping me find the problem.

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

Similar Threads

  1. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 5
    Last Post: 06-19-2013, 10:24 AM
  4. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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