+ Reply to Thread
Results 1 to 12 of 12

Export from Excel to Access but check 2 criteria to ensure no duplicates

  1. #1
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Export from Excel to Access but check 2 criteria to ensure no duplicates

    Hi All,

    As explained in the title I have a spreadsheet where you input your requewsted shifts for the week and then it is exported to access for the Roster manager to work out how many of each are available.

    The code I have for the first part which is just a straight export to access works fine.

    Please Login or Register  to view this content.
    The code that isn't working for me at the moment is:

    Please Login or Register  to view this content.
    I am trying to tweak something saw elsewhere. any help is much appreciated.

  2. #2
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    Anything?

  3. #3
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    When you're accessing an Access database using SQL from Excel, you must encapsulate your variables. For a string variable you must put 'variable' , for a date variable you must put #datevariable#. Also, put a ; at the end of the command line. Finally, you need to pick a cell property. Range("A2") isnt anything. You probably want the .VALUE in cell A2. Oh and it's easier to refer to your sheet name in the range statement....

    eg StrSql = "SELECT * FROM Table1 WHERE USERNAME='" & range("Sheet1!A2").value & "';"

  4. #4
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    Excellent. Will try to incorporate all that. Thank you very much.

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    Also....

    I've never opened a record set using

    Please Login or Register  to view this content.
    I've always done it with...

    Please Login or Register  to view this content.
    and either

    Please Login or Register  to view this content.
    to read into a variable or

    Please Login or Register  to view this content.
    to read into a worksheet.

    You'd then find the record count with either

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.

    But just cos I didn't learn to do what you're doing that way doesn't mean it's wrong.

  6. #6
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    Thanks for the help. I am still struggling to get it to work.


    Please Login or Register  to view this content.
    Can I define x and y as integer even if they are dealing wit haccess record counts? I don't understand why it says object missing.

    Thanks in advance

  7. #7
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    I can't see where you've declared this variable anywhere: dbOpenDynaset

    Shouldn't it be cnn, not dbOpenDynaset?

  8. #8
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    Please Login or Register  to view this content.
    This is not opening the recordset, it is 'saving' teh recordset so that I can carry out a rowcount and transform that into a number.

    I think I am out of my depth here in all honesty. I have never crossed over into SQL and maybe this is too big a job for a relative 'noobie'.

  9. #9
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    try

    Please Login or Register  to view this content.
    instead of

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    Disregard this reply, spotted what I couldn't see in the code.

  11. #11
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    I couldn't see it defined anywhere in the original so assumed it didn't need to be. Is this the best way, off the top of your head to check if the data already exists or can you point me in a direction of a better way to do so.

    Just to clarify, if a username already has a request for given week it comes up error.

    Thanks

  12. #12
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Export from Excel to Access but check 2 criteria to ensure no duplicates

    I am getting an error 91 now. Variable nor with block variable not set.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Check for duplicates against multiple criteria and then concatenate values
    By Pango in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2016, 06:54 PM
  2. [SOLVED] Check for duplicates from two sheets of data based on two criteria (2 columns)
    By mattc_uk in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-23-2014, 10:08 AM
  3. Opening Excel from Access, running Code in Excel then export back to Access
    By JungleJme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2012, 08:49 AM
  4. Export rows to another workbook but check for duplicates
    By revenge4ash89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2012, 06:43 PM
  5. VBA Code to ensure data just sent to Access from Excel are not duplicates
    By mxtreme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2010, 01:25 PM
  6. Export multiple tabs & Ensure that All links are disabled &formats are retained
    By tyrese214 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2010, 09:32 PM
  7. [SOLVED] export access to excel. change access & update excel at same time
    By fastcar in forum Excel General
    Replies: 0
    Last Post: 06-24-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1