Results 1 to 4 of 4
  1. #1
    capsule is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    3

    Thumbs up SOLVING COMMON ERRORS IN ACCESS (Error 1) : Setting Date Field in Recordset to null

    Error 1 : Setting Date Field in Recordset to null



    This Forum helped me a lot and i would like to return the favor ..
    I will save u a lot of time searching for a solution on the internet to the most Frustrated error in ms access in a simple way without too much coding .

    Error 1 : Setting Date Field in Recordset to null " data conversation error 3421 "

    Introduction : I gave up finding a straight solution on the internet for this one , so i came up with my own and it worked , so i hope it will work for you also ..


    Solution : If the field is null set it back to itself .

    Here is a simple dummy example i wrote to demonstrate the solution
    ( look for the bold text in side the code )

    Code :


    Code:
    Sub Event_btnSaveEndTime () 
    
    dim strEndDate as string 
    
    With Form_frmMainForm
    
    strEndTime = .txtEndTime.Value 
    
    rs.Edit
    
    'if the date field is null set it back to itself 
    
    If IsNull(rs.Fields("actEndTime"))  Then
    
    rs.Fields("actEndTime") = rs.Fields("actEndTime")
    
    Else
    
    rs.Fields("actEndTime") = strEndTime
    
    End If
    
    rs.Update
    
    End With 
    
    End Sub

    Note : Keep visiting the forum from time to time , i will keep posting more solutions. For consistency i will use the same format for this thread - Error1 , Error 2 , and so on .


    Best regards to all And happy coding
    Ali - Capsule
    Last edited by capsule; 11-15-2014 at 07:01 PM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Could you explain more about the issue you encountered? I don't really understand the usage and why this was needed. Why would you want field to remain Null if there is input to the textbox?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    capsule is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    3
    OK The usage is this

    scenario setup :

    txtendtime , subfrm that display the recordset data , btnSaveTime , rs

    Usage :

    -ok say u have 2 text boxes for entering endTime and startTime ( they are optional of course ) u can set their value or remove the value and leave them empty .
    -The textbox value whether it is empty or not should be reflected and displayed in the subform that has recordset tied to it , for that u need to update both the table and recordset.
    -The save button have to update both the value in the database ( Using Update Query ) and the record set ( Using the Example i showed above ) so that it refelct and display the result of update .
    -U may say why don't i use rs.requery to refresh the record set value but my project logic doesn't like that


    without the solution :

    You will encounter " data conversion error 3421 " when u hit btnSaveTime ( the update in database will be saved but in the sub form it will not and by that i mean recordset u need to update recordset value using edit - update with solution i mentioned above )

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I am still very confused. Why is an UPDATE query needed to set value in record displayed on form? Why not just populate by reference to field or bound textbox? Don't think I've ever encountered anything like this.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 09-23-2014, 11:32 AM
  2. Replies: 3
    Last Post: 11-13-2013, 08:56 AM
  3. Setting field to null
    By Daryl2106 in forum Access
    Replies: 15
    Last Post: 01-29-2013, 09:12 AM
  4. Replies: 9
    Last Post: 03-26-2012, 10:35 AM
  5. Setting criteria in a calculated date field
    By SteveReberger in forum Access
    Replies: 0
    Last Post: 10-29-2008, 06:58 AM

Tags for this Thread

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