+ Reply to Thread
Results 1 to 9 of 9

VBA Insert Fails with No Error Message

  1. #1
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    VBA Insert Fails with No Error Message

    Hi,

    I'm doing an insert to a table using VBA. Sometimes the coding fails to insert, but it doesn't throw an error in the VBA. If I manually insert a record into that table, I can see that an auto-incremeted field has had a number consumed even though there's no associated record.

    My coding looks like below:

    1. Insert into Address table (Always succeeds)
    Please Login or Register  to view this content.
    2. Query newly added Addresses ID (Always succeeds)
    Please Login or Register  to view this content.
    3. Insert into People table (Sometimes fails)
    Please Login or Register  to view this content.
    *Note that above insert statements are simplified examples, but I have debugged the queries and verified there's no syntax issues, and the addressID returned from step #2 is accurate.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Insert Fails with No Error Message

    What happens when you run the queries directly in Access?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: VBA Insert Fails with No Error Message

    This is my first dive into Access, so please excuse the ignorance, but where do you mean? The VBA is within Access, so I'm guessing there's some way to easily run an ad hoc query outside of VBA.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: VBA Insert Fails with No Error Message

    Try building the queries and running them in the Query Builder. You have not indicated what version of Access you are using (putting this in your profile helps us to answer your issues), so I cannot give you the steps to do this. It varies slightly in the UI on how to find the Query Builder depending on which version you are using.

    In the meantime, you might look at this site on building queries.

    http://www.databasedev.co.uk/queries.html
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: VBA Insert Fails with No Error Message

    I'm on Access 2007. I found the query builder and found out that I have a validation rule violation.

    I have a Text Field where it throws a validation error if I try to insert ''. If I use NULL or 'anyvalue', it works. Are blanks not allowed in Access or is there a setting where I can change this?
    Last edited by yawnzzzz; 04-30-2013 at 08:56 AM.

  6. #6
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: VBA Insert Fails with No Error Message

    Does anyone know why Access would throw a validation error on inserting a blank value? I can put checks everywhere to switch to NULL, but I'd like to understand if that's my only option.

  7. #7
    Forum Contributor vikas.bhandari's Avatar
    Join Date
    04-07-2006
    Location
    Delhi, India
    MS-Off Ver
    Office 2007 and 2010
    Posts
    303

    Re: VBA Insert Fails with No Error Message

    Blank would work if you have allowed in the table to accept blank values. Set the allow Zero length to 'Yes'.

    Untitled.png

    HTH,
    Vikas B

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Insert Fails with No Error Message

    Text fields have a propery Allow Zero length which determines if a null value, eg '', are allowed.

    By default it's set to Yes.

  9. #9
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: VBA Insert Fails with No Error Message

    Thanks for the responses. The Allow Zero Length was set to No for two fields.

    Note to Mod: This thread is Solved, but it's not showing me the Edit button on the first post (although I can see it on all of my other posts).
    Last edited by yawnzzzz; 05-20-2013 at 04:28 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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