Results 1 to 8 of 8
  1. #1
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48

    Data Type Conversion Error

    I have some fields on a form that get updated into a table. If I don't have a value in one of the date fields and I run this function, I receive the error "Data Type Conversion Error". The table this information is getting dumped into has fields formatted as a date. I used the Nz function to help somewhat but now I'm getting this error and am stuck. Any ideas?

    Private Sub CMD_UPDATE_Click()
    Dim CDB As Object
    Dim CRS As Object
    Dim STR_Prop_Name As String
    Dim STR_Prop_Status As String


    Dim STR_TSS_D As String
    Dim STR_DD_R_D As String
    Dim STR_DD_C_D As String
    Dim STR_BOM_Submit_D As String
    Dim STR_Contract_D As String
    Dim STR_Inst_S_D As String
    Dim STR_Inst_E_D As String
    Dim MySQL As String
    STR_Prop_Name = Forms!Frm_Update!LBL_Prop_Name.Caption
    STR_Prop_Status = Forms!Frm_Update!CBO_Prop_Status.Value
    STR_TSS_D = Nz(Forms!Frm_Update!TXT_TSS_COMP_D.Value)
    STR_DD_R_D = Nz(Forms!Frm_Update!TXT_DD_R_D.Value)
    STR_DD_C_D = Nz(Forms!Frm_Update!TXT_DD_C_D.Value)
    STR_BOM_Submit_D = Nz(Forms!Frm_Update!TXT_BOM_Submit_D.Value)
    STR_Contract_D = Nz(Forms!Frm_Update!TXT_Contract_D.Value)
    STR_Inst_S_D = Nz(Forms!Frm_Update!TXT_Inst_S_D.Value)
    STR_Inst_E_D = Nz(Forms!Frm_Update!TXT_Inst_E_D.Value)
    Set CDB = CurrentDb
    MySQL = "SELECT * FROM Master_Table WHERE Prop_Name='" & [Forms]![Frm_Update]![LBL_Prop_Name].Caption & "'"
    Set CRS = CDB.OpenRecordset(MySQL)
    CRS.Edit
    CRS("Prop_Name").Value = STR_Prop_Name
    CRS("Prop_Status").Value = STR_Prop_Status
    CRS("TSS_Completion_Date").Value = STR_TSS_D
    CRS("DD_Rcv_Prop_Specs").Value = STR_DD_R_D
    CRS("DD_Design_Completed").Value = STR_DD_C_D
    CRS("BOM_Submitted_To_Sales").Value = STR_BOM_Submit_D
    CRS("Contract_Date").Value = STR_Contract_D
    CRS("Install_Start_Date").Value = STR_Inst_S_D
    CRS("Install_Completion_Date").Value = STR_Inst_E_D
    CRS.Update
    Set CRS = Nothing
    Set CDB = Nothing
    End Sub

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    A.
    This:
    STR_TSS_D = Nz(Forms!Frm_Update!TXT_TSS_COMP_D.Value)
    . . . looks like it might be an issue because the Nz() function has TWO parameters;
    1. The field/value you are testing for Null [which you have in there]
    2. The value to substitute the Null WITH [which you do not have].
    If you do not provide the second parameter [value_if_null] - Access will provide a zero-length-string.
    If you are trying to put that zero-length-string into your date field you could get that error.

    I'm thinking you should try something like this:
    Code:
    STR_TSS_D = Nz(Forms!Frm_Update!TXT_TSS_COMP_D.Value, Value_To_Use_If_TXT_TSS_COMP_D_Is_Null)
    B.
    In your table design - is the Date field 'Required'?
    If it is, you not only MUST provide a value, but since the field is formatted as 'Date' - you have to provide a valid Date.
    In some test environments that I have worked in, the development team has decided on a date to use for test records. It has always been a date that any User would know was not a possible valid date - for instance 11/11/1111.
    Idon't know what dates your table contains, but see if this gives you something to start with.

    Let us know if you still have problems.

  3. #3
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by Robeen View Post
    A.
    This:

    . . . looks like it might be an issue because the Nz() function has TWO parameters;
    1. The field/value you are testing for Null [which you have in there]
    2. The value to substitute the Null WITH [which you do not have].
    If you do not provide the second parameter [value_if_null] - Access will provide a zero-length-string.
    If you are trying to put that zero-length-string into your date field you could get that error.

    I'm thinking you should try something like this:
    Code:
    STR_TSS_D = Nz(Forms!Frm_Update!TXT_TSS_COMP_D.Value, Value_To_Use_If_TXT_TSS_COMP_D_Is_Null)
    B.
    In your table design - is the Date field 'Required'?
    If it is, you not only MUST provide a value, but since the field is formatted as 'Date' - you have to provide a valid Date.
    In some test environments that I have worked in, the development team has decided on a date to use for test records. It has always been a date that any User would know was not a possible valid date - for instance 11/11/1111.
    Idon't know what dates your table contains, but see if this gives you something to start with.

    Let us know if you still have problems.
    The dates wouldn't be required to the user to enter. Is there any way to not have it enter anything for the fields they leave blank? I know I could do the 11/11/1111 but I would prefer to have it blank or null until they update it if possible. Can this be done?

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Robeen View Post
    ...If you do not provide the second parameter [value_if_null] - Access will provide a zero-length-string.
    Actually, if you don't provide the second parameter, Access will provide a Value appropriate for the DataType of the Field in question; a ZLS for a Text Field, a Zero for a Number Field, and a Date/Time Value value for a Date/Time Field.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by Missinglinq View Post
    Actually, if you don't provide the second parameter, Access will provide a Value appropriate for the DataType of the Field in question; a ZLS for a Text Field, a Zero for a Number Field, and a Date/Time Value value for a Date/Time Field.

    Linq ;0)>
    I thought that was the case as well but I'm still receiving an error when I don't provide that second parameter.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    This

    Dim CRS As Object

    doesn't look correct, given its use, shouldn't it be

    Dim CRS As DAO.Recordset

    And are you really setting the Value of STR_Prop_Name to the Caption of a Label on the Form? Seems a bit odd, but odd things sometime work, of course!


    You might also check for Missing References, especially the DAO Library for your Access version.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    graviz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    48
    Quote Originally Posted by Missinglinq View Post
    This

    Dim CRS As Object

    doesn't look correct, given its use, shouldn't it be

    Dim CRS As DAO.Recordset

    And are you really setting the Value of STR_Prop_Name to the Caption of a Label on the Form? Seems a bit odd, but odd things sometime work, of course!


    You might also check for Missing References, especially the DAO Library for your Access version.

    Linq ;0)>
    The caption is correct. It's only to show the name of a property and it's populated from a search form before this one. I don't want the user to change it (i.e. textbox) so I made it into a lable.

    I don't think the declaring is the issue. If I use the "11/11/1111" as Robeen states above it works fine. The problem is I really don't want to have that dummy value in the table.

    If I go into the actual table an do a paste append (and don't include all date fields) it works perfectly. This is why I would think something like this should be possible.

  8. #8
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Quote Originally Posted by Missinglinq View Post
    Actually, if you don't provide the second parameter, Access will provide a Value appropriate for the DataType of the Field in question; a ZLS for a Text Field, a Zero for a Number Field, and a Date/Time Value value for a Date/Time Field.

    Linq ;0)>
    I was going by information on these two sites:
    1.
    http://office.microsoft.com/en-us/ac...001228890.aspx
    If you use the Nz function in an expression in a query without using the valueifnull argument, the results will be a zero-length string in the fields that contain null values.
    http://www.techonthenet.com/access/f...dvanced/nz.php
    value_if_null is optional. It is the value to use when the variant is a null value. If this parameter is omitted and the variant is a null value, the Nz function will return a zero or a zero-length string.
    . . . but I haven't tested . . . so there may be something in what you say.
    What do you think the Nz() function will put into a Date field if the 'value-if-null' is ommited - an actual date?

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

Similar Threads

  1. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  2. Conversion made on Field type for liked tables
    By crismroman in forum Access
    Replies: 4
    Last Post: 02-15-2012, 03:59 AM
  3. Help need: Type conversion failure
    By tami in forum Access
    Replies: 1
    Last Post: 01-18-2012, 07:18 AM
  4. Type Conversion Failure
    By fpmsi in forum Access
    Replies: 7
    Last Post: 09-22-2011, 11:25 AM
  5. Data Type Conversion in Query
    By EHittner in forum Queries
    Replies: 3
    Last Post: 04-14-2010, 02:11 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