Results 1 to 4 of 4
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    change default value within an existing table - error 3219

    writing code to change the default value of a field (data type: Long Integer) within an existing table and getting an error: 3219
    the value of NewSize = 3

    Any thoughts / suggestions / "take-a-look-at's "... will (as always) be greatly appreciated in advance,
    m.


    Code:
    Function ChangeDefaultValue(ByVal vFilePath As Variant, TblName As String, FldName As String, NewSize As Integer)
        Dim Td As TableDef
        Dim DbPath As Variant
        Dim rs As Recordset
        
        On Error Resume Next
    
        If IsNull(DbPath) Then
            Set gsDbs = CurrentDb    'if local table
        Else
             Set gsDbs = OpenDatabase(vFilePath)    'if linked table
            If Err <> 0 Then
                'failed to open back end database
                Exit Function
            End If
        End If
    
        'get table
        Set Td = gsDbs.TableDefs(TblName)
        If Err <> 0 Then
            'failed to get table
            GoTo Done
        End If
    
        'change default value size
        If Td.Fields(FldName).DefaultValue <> NewSize Then
            With Td
    
    '---> the error occurs with this portion of the code:
    
                Set rs = gsDbs.OpenRecordset(TblName)
                    rs.Fields(FldName).DefaultValue = NewSize
                rs.Close
            End With
            
            If Err <> 0 Then GoTo Done
    
        End If
    
        ChangeDefaultValue = True  'defaults to false if it fails to get here
    
    Done:
        If Not gsDbs Is Nothing Then gsDbs.Close
    End Function


  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    if this is a permanent change, would have thought you would use

    Code:
    With Td
     .DefaultValue = NewSize
    End With

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I've not done this but would expect that
    a) you cannot alter a table field using a recordset field reference
    b) you cannot alter a table field when there is a hold on it by way of query, recordset, form, report, whatever

    and you are doing both of these things.

    If the table field does not have the property you're trying to alter, then you must create it first. Just saying that in for future reference in case you're not aware. I don't know if a table field has this property if it has never been set. On the other hand, if this is a one-off, why don't you just change it in design view?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    would not be the first time i 'over-coded into an error'

    worked exactly as needed THNX!

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

Similar Threads

  1. Replies: 5
    Last Post: 05-29-2018, 04:50 AM
  2. Insanity with Runtime Error 3219
    By sanderson in forum Programming
    Replies: 3
    Last Post: 10-30-2015, 07:10 AM
  3. Dcount of Query in VBA gives Error 3219
    By krausr79 in forum Access
    Replies: 2
    Last Post: 10-20-2014, 12:00 PM
  4. Replies: 7
    Last Post: 02-06-2012, 11:54 AM
  5. runtime error 3219
    By Rider570 in forum Programming
    Replies: 3
    Last Post: 07-07-2010, 09:12 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