![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm having a little problem with this Update statement and have been toiling away to no good. Could anyone please correct my syntax. Here's the code: CurrentDb.Execute "UPDATE JVTable SET JVTable.INV_DATE = " & DMY(Me.Txt_Date) & ", " _ "JVTable.RcdFm_PdTo = '" & nz(me.txt_RcdFm_PdTo) & "'" _ "JVTable.Chq_No = '" & nz(me.txt_Chq_No) & "'" _ "JVTable.Chq_Date = '" & DMY(Me.Txt_Date) & ", " _ "JVTable.Bank = '" & nz(me.txt_Bank) & "'" _ "JVTable.Settled_Bill_No = '" & nz(me.txt_Settled_Bill_No) & "'" Best Rgds, Prakash |
#3
| |||
| |||
|
|
The string you need will depend on the data types of your various fields. For a Date/Time field, you need to delimit the value with #. For Text fields, use quotes. For number fields, you don't need any delimiter. Additionally, the Nz() is not adequate here. You need the word Null in the string if the field is null (and so you are trying to insert the Null value.) The literal date in the SQL string needs to be in mdy format (not your own local format.) It will be easier of you build a string, because you can then examine the contents to see if it looks right. The following example demonstrates the different data type, on the assumption that: INV_DATE is a Date/Time field, and RcdFm_PdTo is a Number field, and Chq_No is a Text field. Adjust and complete the string to suit. The example prints the string to the Immediate Window. If it fails, press Ctrl+G and look at the string. Compare it with a query that does work, and see where you went wrong. Here's the incomplete example that illustrates the different data types: Dim strSql As String Const strcJetDate "\#mm\/dd\/yyyy\#" strSql = "UPDATE JVTable SET INV_DATE = " & _ IIf(IsNull(Me.txt_Date), "Null", Format(Me.txt_Date, strcJetDate)) & _ ", RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", Me.txt_RcdFm_PdTo) & _ ", Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & _ ... Debug.Print strSql CurrentDb.Execute strSql, dbFailOnError -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. prakashwadhw... (AT) gmail (DOT) com> wrote in message news:6809ebe0-5500-490f-9eac-a3afe57c1766 (AT) v3g2000hsc (DOT) googlegroups.com... I'm having a little problem with this Update statement and have been toiling away to no good. Could anyone please correct my syntax. Here's the code: CurrentDb.Execute "UPDATE JVTable SET JVTable.INV_DATE = " & DMY(Me.Txt_Date) & ", " _ "JVTable.RcdFm_PdTo = '" & nz(me.txt_RcdFm_PdTo) & "'" _ "JVTable.Chq_No = '" & nz(me.txt_Chq_No) & "'" _ "JVTable.Chq_Date = '" & DMY(Me.Txt_Date) & ", " _ "JVTable.Bank = '" & nz(me.txt_Bank) & "'" _ "JVTable.Settled_Bill_No = '" & nz(me.txt_Settled_Bill_No) & "'" Best Rgds, Prakash |
#4
| |||
| |||
|
|
Two questions: (pls excuse my ignorance) 1) You've used the word "Null" in the iif statement. Does that actually input the string "Null" into the field or just the NULL value ? |
|
2) What does the dbFailOnError do ? |
|
Thank you very, very, much. Best Rgds, Prakash. |
#5
| |||
| |||
|
|
On Feb 26, 2:52 pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote: The string you need will depend on the data types of your various fields. For a Date/Time field, you need to delimit the value with #. For Text fields, use quotes. For number fields, you don't need any delimiter. Additionally, the Nz() is not adequate here. You need the word Null in the string if the field is null (and so you are trying to insert the Null value.) The literal date in the SQL string needs to be in mdy format (not your own local format.) It will be easier of you build a string, because you can then examine the contents to see if it looks right. The following example demonstrates the different data type, on the assumption that: INV_DATE is a Date/Time field, and RcdFm_PdTo is a Number field, and Chq_No is a Text field. Adjust and complete the string to suit. The example prints the string to the Immediate Window. If it fails, press Ctrl+G and look at the string. Compare it with a query that does work, and see where you went wrong. Here's the incomplete example that illustrates the different data types: Dim strSql As String Const strcJetDate "\#mm\/dd\/yyyy\#" strSql = "UPDATE JVTable SET INV_DATE = " & _ IIf(IsNull(Me.txt_Date), "Null", Format(Me.txt_Date, strcJetDate)) & _ ", RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", Me.txt_RcdFm_PdTo) & _ ", Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & _ ... Debug.Print strSql CurrentDb.Execute strSql, dbFailOnError -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. prakashwadhw... (AT) gmail (DOT) com> wrote in message news:6809ebe0-5500-490f-9eac-a3afe57c1766 (AT) v3g2000hsc (DOT) googlegroups.com... I'm having a little problem with this Update statement and have been toiling away to no good. Could anyone please correct my syntax. Here's the code: CurrentDb.Execute "UPDATE JVTable SET JVTable.INV_DATE = " & DMY(Me.Txt_Date) & ", " _ "JVTable.RcdFm_PdTo = '" & nz(me.txt_RcdFm_PdTo) & "'" _ "JVTable.Chq_No = '" & nz(me.txt_Chq_No) & "'" _ "JVTable.Chq_Date = '" & DMY(Me.Txt_Date) & ", " _ "JVTable.Bank = '" & nz(me.txt_Bank) & "'" _ "JVTable.Settled_Bill_No = '" & nz(me.txt_Settled_Bill_No) & "'" Best Rgds, Prakash Thx Allen !! You've really covered almost all sides here. Firstly, besides the 2 dates ... they are all text fields (I should've specified that at the outset ...Sorry !!) Secondly, my DMY function takes care of the dates by delimiting with #, etc. Two questions: (pls excuse my ignorance) 1) You've used the word "Null" in the iif statement. Does that actually input the string "Null" into the field or just the NULL value ? 2) What does the dbFailOnError do ? I toyed around with your example & tailored it to suit my needs. It seems to work. Here's my code ... StrSql = "UPDATE JVTable SET JVTable.INV_DATE = " & _ IIf(IsNull(Me.Txt_Date), "Null", DMY(Me.Txt_Date)) & ", " & _ "JVTable.RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", """" & Me.txt_RcdFm_PdTo & """") & ", " & _ "JVTable.Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & ", " & _ "JVTable.Chq_Date = " & _ IIf(IsNull(Me.txt_Chq_Date), "Null", DMY(Me.txt_Chq_Date)) & ", " & _ "JVTable.Bank = " & _ IIf(IsNull(Me.txt_Bank), "Null", """" & Me.txt_Bank & """") & ", " & _ "JVTable.Settled_Bill_No = " & _ IIf(IsNull(Me.txt_Settled_Bill_Nos), "Null", """" & Me.txt_Settled_Bill_Nos & """") If I have any further difficulty, I'll post back. Thank you very, very, much. Best Rgds, Prakash. |
#6
| |||
| |||
|
|
If I leave txt_Chq_Date empty on the form i get the message "Invalid Use of Null" After I fill all the fields and try to run the sql i get: "Too few Parameters. Expected 1." Can anyone please point out where I'm going wrong ? Best Rgds, Prakash. |
#7
| |||
| |||
|
|
On Feb 26, 3:58 pm, prakashwadhw... (AT) gmail (DOT) com wrote: On Feb 26, 2:52 pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote: The string you need will depend on the data types of your various fields. For a Date/Time field, you need to delimit the value with #. For Text fields, use quotes. For number fields, you don't need any delimiter. Additionally, the Nz() is not adequate here. You need the word Null in the string if the field is null (and so you are trying to insert the Null value.) The literal date in the SQL string needs to be in mdy format (not your own local format.) It will be easier of you build a string, because you can then examine the contents to see if it looks right. The following example demonstrates the different data type, on the assumption that: INV_DATE is a Date/Time field, and RcdFm_PdTo is a Number field, and Chq_No is a Text field. Adjust and complete the string to suit. The example prints the string to the Immediate Window. If it fails, press Ctrl+G and look at the string. Compare it with a query that does work, and see where you went wrong. Here's the incomplete example that illustrates the different data types: Dim strSql As String Const strcJetDate "\#mm\/dd\/yyyy\#" strSql = "UPDATE JVTable SET INV_DATE = " & _ IIf(IsNull(Me.txt_Date), "Null", Format(Me.txt_Date, strcJetDate)) & _ ", RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", Me.txt_RcdFm_PdTo) & _ ", Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & _ ... Debug.Print strSql CurrentDb.Execute strSql, dbFailOnError -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. prakashwadhw... (AT) gmail (DOT) com> wrote in message news:6809ebe0-5500-490f-9eac-a3afe57c1766 (AT) v3g2000hsc (DOT) googlegroups.com... I'm having a little problem with this Update statement and have been toiling away to no good. Could anyone please correct my syntax. Here's the code: CurrentDb.Execute "UPDATE JVTable SET JVTable.INV_DATE = " & DMY(Me.Txt_Date) & ", " _ "JVTable.RcdFm_PdTo = '" & nz(me.txt_RcdFm_PdTo) & "'" _ "JVTable.Chq_No = '" & nz(me.txt_Chq_No) & "'" _ "JVTable.Chq_Date = '" & DMY(Me.Txt_Date) & ", " _ "JVTable.Bank = '" & nz(me.txt_Bank) & "'" _ "JVTable.Settled_Bill_No = '" & nz(me.txt_Settled_Bill_No) & "'" Best Rgds, Prakash Thx Allen !! You've really covered almost all sides here. Firstly, besides the 2 dates ... they are all text fields (I should've specified that at the outset ...Sorry !!) Secondly, my DMY function takes care of the dates by delimiting with #, etc. Two questions: (pls excuse my ignorance) 1) You've used the word "Null" in the iif statement. Does that actually input the string "Null" into the field or just the NULL value ? 2) What does the dbFailOnError do ? I toyed around with your example & tailored it to suit my needs. It seems to work. Here's my code ... StrSql = "UPDATE JVTable SET JVTable.INV_DATE = " & _ IIf(IsNull(Me.Txt_Date), "Null", DMY(Me.Txt_Date)) & ", " & _ "JVTable.RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", """" & Me.txt_RcdFm_PdTo & """") & ", " & _ "JVTable.Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & ", " & _ "JVTable.Chq_Date = " & _ IIf(IsNull(Me.txt_Chq_Date), "Null", DMY(Me.txt_Chq_Date)) & ", " & _ "JVTable.Bank = " & _ IIf(IsNull(Me.txt_Bank), "Null", """" & Me.txt_Bank & """") & ", " & _ "JVTable.Settled_Bill_No = " & _ IIf(IsNull(Me.txt_Settled_Bill_Nos), "Null", """" & Me.txt_Settled_Bill_Nos & """") If I have any further difficulty, I'll post back. Thank you very, very, much. Best Rgds, Prakash. If I leave txt_Chq_Date empty on the form i get the message "Invalid Use of Null" After I fill all the fields and try to run the sql i get: "Too few Parameters. Expected 1." Can anyone please point out where I'm going wrong ? Best Rgds, Prakash. |
#8
| |||
| |||
|
|
Post the SQL statement, i.e. results you get from: Debug.Print strSql -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. prakashwadhw... (AT) gmail (DOT) com> wrote in message If I leave txt_Chq_Date empty on the form i get the message "Invalid Use of Null" After I fill all the fields and try to run the sql i get: "Too few Parameters. Expected 1." Can anyone please point out where I'm going wrong ? Best Rgds, Prakash. |
#9
| |||
| |||
|
|
prakashwadhw... (AT) gmail (DOT) com wrote: On Feb 26, 3:58 pm, prakashwadhw... (AT) gmail (DOT) com wrote: On Feb 26, 2:52 pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote: The string you need will depend on the data types of your various fields. For a Date/Time field, you need to delimit the value with #. For Text fields, use quotes. For number fields, you don't need any delimiter. Additionally, the Nz() is not adequate here. You need the word Null in the string if the field is null (and so you are trying to insert the Null value.) The literal date in the SQL string needs to be in mdy format (not your own local format.) It will be easier of you build a string, because you can then examine the contents to see if it looks right. The following example demonstrates the different data type, on the assumption that: INV_DATE is a Date/Time field, and RcdFm_PdTo is a Number field, and Chq_No is a Text field. Adjust and complete the string to suit. The example prints the string to the Immediate Window. If it fails, press Ctrl+G and look at the string. Compare it with a query that does work, and see where you went wrong. Here's the incomplete example that illustrates the different data types: Dim strSql As String Const strcJetDate "\#mm\/dd\/yyyy\#" strSql = "UPDATE JVTable SET INV_DATE = " & _ IIf(IsNull(Me.txt_Date), "Null", Format(Me.txt_Date, strcJetDate)) & _ ", RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", Me.txt_RcdFm_PdTo) & _ ", Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & _ ... Debug.Print strSql CurrentDb.Execute strSql, dbFailOnError -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. prakashwadhw... (AT) gmail (DOT) com> wrote in message news:6809ebe0-5500-490f-9eac-a3afe57c1766 (AT) v3g2000hsc (DOT) googlegroups.com... I'm having a little problem with this Update statement and have been toiling away to no good. Could anyone please correct my syntax. Here's the code: CurrentDb.Execute "UPDATE JVTable SET JVTable.INV_DATE = " & DMY(Me.Txt_Date) & ", " _ "JVTable.RcdFm_PdTo = '" & nz(me.txt_RcdFm_PdTo) & "'" _ "JVTable.Chq_No = '" & nz(me.txt_Chq_No) & "'" _ "JVTable.Chq_Date = '" & DMY(Me.Txt_Date) & ", " _ "JVTable.Bank = '" & nz(me.txt_Bank) & "'" _ "JVTable.Settled_Bill_No = '" & nz(me.txt_Settled_Bill_No) & "'" Best Rgds, Prakash Thx Allen !! You've really covered almost all sides here. Firstly, besides the 2 dates ... they are all text fields (I should've specified that at the outset ...Sorry !!) Secondly, my DMY function takes care of the dates by delimiting with #, etc. Two questions: (pls excuse my ignorance) 1) You've used the word "Null" in the iif statement. Does that actually input the string "Null" into the field or just the NULL value ? 2) What does the dbFailOnError do ? I toyed around with your example & tailored it to suit my needs. It seems to work. Here's my code ... StrSql = "UPDATE JVTable SET JVTable.INV_DATE = " & _ IIf(IsNull(Me.Txt_Date), "Null", DMY(Me.Txt_Date)) & ", " & _ "JVTable.RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", """" & Me.txt_RcdFm_PdTo & """") & ", " & _ "JVTable.Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & ", " & _ "JVTable.Chq_Date = " & _ IIf(IsNull(Me.txt_Chq_Date), "Null", DMY(Me.txt_Chq_Date)) & ", " & _ "JVTable.Bank = " & _ IIf(IsNull(Me.txt_Bank), "Null", """" & Me.txt_Bank & """") & ", " & _ "JVTable.Settled_Bill_No = " & _ IIf(IsNull(Me.txt_Settled_Bill_Nos), "Null", """" & Me.txt_Settled_Bill_Nos & """") If I have any further difficulty, I'll post back. Thank you very, very, much. Best Rgds, Prakash. If I leave txt_Chq_Date empty on the form i get the message "Invalid Use of Null" After I fill all the fields and try to run the sql i get: "Too few Parameters. Expected 1." Can anyone please point out where I'm going wrong ? Best Rgds, Prakash. If you have something like Debug.Print strSQL and it fails, one thing you can do is to create a new query (Query/New/Design/Close. You now have a blank Query builder. Now go into the Debug/Immediate window. You'll see the offending strSQL line. Copy it to the clipboard. Go back the the Query builder and select View/SQL and paste the code into the query window. Now run it either from that window or the Design window. This might help track down the error. |
#10
| |||
| |||
|
|
prakashwadhw... (AT) gmail (DOT) com wrote: On Feb 26, 3:58 pm, prakashwadhw... (AT) gmail (DOT) com wrote: On Feb 26, 2:52 pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote: The string you need will depend on the data types of your various fields. For a Date/Time field, you need to delimit the value with #. For Text fields, use quotes. For number fields, you don't need any delimiter. Additionally, the Nz() is not adequate here. You need the word Null in the string if the field is null (and so you are trying to insert the Null value.) The literal date in the SQL string needs to be in mdy format (not your own local format.) It will be easier of you build a string, because you can then examine the contents to see if it looks right. The following example demonstrates the different data type, on the assumption that: INV_DATE is a Date/Time field, and RcdFm_PdTo is a Number field, and Chq_No is a Text field. Adjust and complete the string to suit. The example prints the string to the Immediate Window. If it fails, press Ctrl+G and look at the string. Compare it with a query that does work, and see where you went wrong. Here's the incomplete example that illustrates the different data types: Dim strSql As String Const strcJetDate "\#mm\/dd\/yyyy\#" strSql = "UPDATE JVTable SET INV_DATE = " & _ IIf(IsNull(Me.txt_Date), "Null", Format(Me.txt_Date, strcJetDate)) & _ ", RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", Me.txt_RcdFm_PdTo) & _ ", Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & _ ... Debug.Print strSql CurrentDb.Execute strSql, dbFailOnError -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. prakashwadhw... (AT) gmail (DOT) com> wrote in message news:6809ebe0-5500-490f-9eac-a3afe57c1766 (AT) v3g2000hsc (DOT) googlegroups.com... I'm having a little problem with this Update statement and have been toiling away to no good. Could anyone please correct my syntax. Here's the code: CurrentDb.Execute "UPDATE JVTable SET JVTable.INV_DATE = " & DMY(Me.Txt_Date) & ", " _ "JVTable.RcdFm_PdTo = '" & nz(me.txt_RcdFm_PdTo) & "'" _ "JVTable.Chq_No = '" & nz(me.txt_Chq_No) & "'" _ "JVTable.Chq_Date = '" & DMY(Me.Txt_Date) & ", " _ "JVTable.Bank = '" & nz(me.txt_Bank) & "'" _ "JVTable.Settled_Bill_No = '" & nz(me.txt_Settled_Bill_No) & "'" Best Rgds, Prakash Thx Allen !! You've really covered almost all sides here. Firstly, besides the 2 dates ... they are all text fields (I should've specified that at the outset ...Sorry !!) Secondly, my DMY function takes care of the dates by delimiting with #, etc. Two questions: (pls excuse my ignorance) 1) You've used the word "Null" in the iif statement. Does that actually input the string "Null" into the field or just the NULL value ? 2) What does the dbFailOnError do ? I toyed around with your example & tailored it to suit my needs. It seems to work. Here's my code ... StrSql = "UPDATE JVTable SET JVTable.INV_DATE = " & _ IIf(IsNull(Me.Txt_Date), "Null", DMY(Me.Txt_Date)) & ", " & _ "JVTable.RcdFm_PdTo = " & _ IIf(IsNull(Me.txt_RcdFm_PdTo), "Null", """" & Me.txt_RcdFm_PdTo & """") & ", " & _ "JVTable.Chq_No = " & _ IIf(IsNull(Me.txt_Chq_No), "Null", """" & Me.txt_Chq_No & """") & ", " & _ "JVTable.Chq_Date = " & _ IIf(IsNull(Me.txt_Chq_Date), "Null", DMY(Me.txt_Chq_Date)) & ", " & _ "JVTable.Bank = " & _ IIf(IsNull(Me.txt_Bank), "Null", """" & Me.txt_Bank & """") & ", " & _ "JVTable.Settled_Bill_No = " & _ IIf(IsNull(Me.txt_Settled_Bill_Nos), "Null", """" & Me.txt_Settled_Bill_Nos & """") If I have any further difficulty, I'll post back. Thank you very, very, much. Best Rgds, Prakash. If I leave txt_Chq_Date empty on the form i get the message "Invalid Use of Null" After I fill all the fields and try to run the sql i get: "Too few Parameters. Expected 1." Can anyone please point out where I'm going wrong ? Best Rgds, Prakash. If you have something like Debug.Print strSQL and it fails, one thing you can do is to create a new query (Query/New/Design/Close. You now have a blank Query builder. Now go into the Debug/Immediate window. You'll see the offending strSQL line. Copy it to the clipboard. Go back the the Query builder and select View/SQL and paste the code into the query window. Now run it either from that window or the Design window. This might help track down the error. |
![]() |
| Thread Tools | |
| Display Modes | |
| |