Results 1 to 7 of 7
  1. #1
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85

    Append error statement workaround

    I would like to use a combobox selection as the parameter in a query. I have table called immigrantstbl which has a primary key field called aliennumber and a second field called casenumber. Members of the same family will each have a unique aliennumber but they will all have the same casenumber. I want to use a select query to select a specific case number and when I create a combobox on the field casenumber I find, not surprisingly, that there are multiple duplicates of the same number. To remove this duplication I decided to append the immigrantstbl to a new table tempimmigrantstbl, where the casenumber field is a primary key but, of course, I get an error message saying that not all the records could append because of the violation of the primary key constraints. I can say "Yes" (manually) to the "do I want to run the append query anyway" question, but I would like to be able to include an automatic "Yes" in the code. Any suggestions?

    Thanks for all the help.

    Ron C

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If you are manually running the append action from a query object in the NavigationPane, cannot prevent the popup warning. Use code instead (macro or VBA).

    DoCmd.SetWarnings False
    ...
    DoCmd.SetWarnings True

    or

    CurrentDb.Execute ...

    If you have code, then post it for analysis.


    Your object names would be easier to read if you use CamelCase, ex: AlienNumber, TempImmigrantsTBL. Most developers put the object type in prefix instead of suffix: tblTempImmigrants.
    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
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    Thanks for the information. I appreciate it, also for the guidance on nomenclature. Question: does code ignore case?

    Ron C

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Access and VBA are not case sensitive by default.

    So, in brief, yes.
    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
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    I want to use a select query
    To remove this duplication I decided to append...
    Is this not 2 different situations? It reads like you made more work for yourself by dealing with the first problem in such a fashion. If the combo rowsource is based on a query, and that query returns duplicate values, then I think the right approach is to prevent that by modifying the combo query. Perhaps all you need is the SELECT DISTINCT predicate in your query properties (in design view, right click on query background if property sheet isn't visible). Try Distinct Rows or Distinct Values (you cannot have both) and see if either gives you a list of single choices, or post your combo rowsource sql with some info about what it's based on.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Good points Micron.

    Roncc, are you doing this with the goal of creating a table where the casenumber will be unique value and so then immigrantstbl will be a related dependent table? Do you want to generate an autonumber unique ID in the casenumber table that will then be saved into immigrantstbl as a foreign key?

    Otherwise, as Micron states, the casenumber table is not necessary.
    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
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    Thank you.

    Ron C

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

Similar Threads

  1. Append SQL Statement expression
    By Jgk in forum Queries
    Replies: 5
    Last Post: 05-16-2014, 05:56 PM
  2. Run Append Query From If Statement
    By scoe in forum Queries
    Replies: 2
    Last Post: 04-02-2014, 07:41 AM
  3. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. Append Query with IIF statement
    By Cheshire101 in forum Queries
    Replies: 5
    Last Post: 09-16-2010, 12:51 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