Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    Error on insert into command

    In my form I have created a button and added an insert into code. But on click event it crashes and shows following errors.
    Click image for larger version. 

Name:	Err.jpg 
Views:	40 
Size:	33.2 KB 
ID:	43512
    and
    Click image for larger version. 

Name:	Err1.jpg 
Views:	39 
Size:	79.3 KB 
ID:	43513


    Db is as attached.
    Insert.zip

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    methd is a string.
    change end of Sq string to:

    newamount & ", '" & methd & "' );"

  3. #3
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by davegri View Post
    methd is a string.
    change end of Sq string to:

    newamount & ", '" & methd & "' );"
    Thanks mate. I works.... But on the date field it puts time instead of a date value.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Need delimiters for date also:
    & CONSID & " , " & FKCNFID & " , #" & dt & "# , " & newAmount & " , '" & methd & "' );"

  5. #5
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by davegri View Post
    Need delimiters for date also:
    & CONSID & " , " & FKCNFID & " , #" & dt & "# , " & newAmount & " , '" & methd & "' );"
    Cheers mate!
    But what if I want to insert a NULL value to the 2nd field (ie. CONSID) instead of Me.Cons_ID value?

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Insert-davegri-v01.zip

    See attached.
    Had to make too many adjustments to show in this message.
    Removed table validation constraints for "values >0" so that null was allowed.
    Changed Dim of CONSID to variant to allow for null assignment
    Added record to lookup table _cnflookup to include a null (blank) selection in the combobox dropdown.
    Changed some keys from integer to long
    Last edited by davegri; 11-29-2020 at 11:12 AM. Reason: clarif

  7. #7
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by davegri View Post
    Insert-davegri-v01.zip

    See attached.
    Had to make too many adjustments to show in this message.
    Removed table validation constraints for "values >0" so that null was allowed.
    Changed Dim of CONSID to variant to allow for null assignment
    Added record to lookup table _cnflookup to include a null (blank) selection in the combobox dropdown.
    Changed some keys from integer to long
    I think there had been a misinterpretation between us. What I was looking for was to insert Null instead of CONSID, which looks like achievable by placing & "NULL" & " , " & FKCNFID & instead of CONSID in the insert statement.
    However 0 in the FK_CNFID field of payment_CNF table shows blank when represented through the CNF_ID combobox. Why is so?

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    I think there had been a misinterpretation between us. What I was looking for was to insert Null instead of CONSID, which looks like achievable by placing & "NULL" & " , " & FKCNFID & instead of CONSID in the insert statement.
    However 0 in the FK_CNFID field of payment_CNF table shows blank when represented through the CNF_ID combobox. Why is so?
    Yes, but that requires a different SQL string, while the original is still required when CONSID is not null. In my change, the SQL string will handle both.
    The blank row in CNF_ID combobox allows you to select a null value to insert as you requested in post #5.

  9. #9
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by davegri View Post
    Yes, but that requires a different SQL string, while the original is still required when CONSID is not null. In my change, the SQL string will handle both.
    The blank row in CNF_ID combobox allows you to select a null value to insert as you requested in post #5.
    Hi Dave.
    I need some time to grasp your code.
    But at the moment facing a weird problem. The date which is copied and the date which is saved on insert event does not remain the same. In my PC I use British date format. dd/mm/yy. When the append query runs the values of the date parts get interchanged. Hence makes it a different date.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Use a format for the correct storage.

    I use a constant as I can never remember the correct syntax.

    Code:
    Public Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Needed for dates in queries as Access expects USA format.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by Welshgasman View Post
    Use a format for the correct storage.

    I use a constant as I can never remember the correct syntax.

    Code:
    Public Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Needed for dates in queries as Access expects USA format.
    How to use it?

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    You use it to format the date.?

    Lookup the Format() function.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by Welshgasman View Post
    You use it to format the date.?

    Lookup the Format() function.
    I have wrapped the variable of the insert sql with Format function as below.

    Code:
    Format(dt, "yyyy-mm-dd")

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by bubai View Post
    I have wrapped the variable of the insert sql with Format function as below.

    Code:
    Format(dt, "yyyy-mm-dd")
    You were meant to use my constant and not "yyyy-mm-dd", but if it works, leave it as it is. Normally I would use the # delimiter.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    bubai is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Quote Originally Posted by Welshgasman View Post
    You were meant to use my constant and not "yyyy-mm-dd", but if it works, leave it as it is. Normally I would use the # delimiter.
    # delimiter was there.
    Code:
    " , #" & Format(dt, "yyyy-mm-dd") & "# , "
    But in case of using the constant do I just change it's declaration as below?
    Code:
    Const dt = Me.Paid_Dt
    any other change?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 08-21-2020, 03:49 PM
  2. how to format a string on insert command
    By geotrouvetout67 in forum Programming
    Replies: 7
    Last Post: 08-30-2019, 04:24 PM
  3. Replies: 3
    Last Post: 03-16-2016, 11:07 AM
  4. Arguement not optional - INSERT INTO sql command
    By shabbaranks in forum Programming
    Replies: 5
    Last Post: 04-24-2013, 09:42 AM
  5. Replies: 5
    Last Post: 03-04-2012, 01:21 PM

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