Results 1 to 7 of 7

Thread: trying to set default properties with ALTER TABLE help?

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    trying to set default properties with ALTER TABLE help?

    I have read through about a 4 pages of threads trying to find a solution and it could be there isnt one. I am using ODBC provider to connect to my Access database. I need to add two fields and set one field default settings to 'FALSE'.

    The following gives me a syntax error in constraint clause. I have tried a variety of diffrent ways to do this, but I am beginning to think, you cant set the default settings.

    I would appreciate any help.



    VB Code:
    1. 'modify table
    2.     Call CreateConnection(objConn)
    3.         objConn.Execute "ALTER TABLE Documents ADD n_mp3 TEXT(50) NOT NULL"
    4.         objConn.Execute "ALTER TABLE Documents ADD n_wavBol TEXT(50) CONSTRAINT DEFAULT 'False'"
    5.     Call CloseConnection(objConn)
    He who never made a mistake never made a discovery?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: trying to set default properties with ALTER TABLE help?

    I only found 11 threads for Access (SQL varies by DBMS ), and the suggestion each time was similar to what you have, except for one minor change...

    Have you tried without the Constraint keyword?
    eg:
    VB Code:
    1. objConn.Execute "ALTER TABLE Documents ADD n_wavBol TEXT(50) DEFAULT 'False'"

  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: trying to set default properties with ALTER TABLE help?

    Yes I have tried this but it does not add the field and I get an error

    -2147217900,"[Microsoft][ODBC Microsoft Access Driver] Syntax error in ALTER TABLE statement.","This error created on:",#2006-01-19 07:53:49#



    --edited

    I don't know if this makes any difference but the database is MS Access 2000 file format.
    Last edited by Navarone; Jan 19th, 2006 at 08:05 AM.
    He who never made a mistake never made a discovery?

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: trying to set default properties with ALTER TABLE help?

    How about you try it with OLEDB provider?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: trying to set default properties with ALTER TABLE help?

    I tried but I ran into problems and didn't know how to fix them. In my module I have this set up;
    VB Code:
    1. Sub CreateConnection(objConn As Connection)
    2.  
    3. ' CONNECTION STRING FOR THE DATABASE
    4. '    AccessConnect = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    5. '                    "DBQ=Westfield.MDB;" & _
    6. '                    "DefaultDir=" & App.Path & ";"
    7.  
    8. AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    9.                  "Data Source=Westfield.mdb;" & _
    10.                  "DefaultDir=" & App.Path & ";"
    11.                      
    12.                      'MsgBox AccessConnect
    13.  
    14.     ' Create Connection Object and open it
    15.     Set objConn = New ADODB.Connection
    16.  
    17.     objConn.CursorLocation = adUseClient
    18.  
    19.     ' Trap any error/exception
    20.     On Error GoTo AdoError
    21.  
    22.     objConn.ConnectionString = AccessConnect
    23.     objConn.Open
    24.  
    25.     Exit Sub
    26.  
    27.     ' ADO Error/Exception Handler
    28. AdoError:
    29.     ErrNumber = Err.Number
    30.     ErrSource = Err.Source
    31.     ErrDescription = Err.Description
    32.  
    33.     'AdoErrorEx List1, objConn
    34.  
    35. End Sub
    36.  
    37. Sub CloseConnection(objConn As Connection)
    38.  
    39.     objConn.Close
    40.     Set objConn = Nothing
    41.  
    42. End Sub

    When I run the application I get an error when I call the objConn and bombs out in the With OBJRS statement on the .ActiveConnection = objConn in the code below. I am not sure why. Maybe I am missing something in the References? Do you know why this might happen?

    VB Code:
    1. 'connect to database, generate ID, add ID to text box
    2.     Call CreateConnection(objConn)
    3.  
    4.     'MsgBox objConn.State
    5.     Set objRs = New ADODB.Recordset
    6.  
    7.     With objRs
    8.         .ActiveConnection = objConn
    9.         .CursorLocation = adUseClient
    10.         .CursorType = adOpenDynamic
    11.         .LockType = adLockOptimistic
    12.         .Source = "select * from Campaign where 2=3"    '2=3 basically creates a empty record set
    13.         .Open
    14.     End With
    15.  
    16.     '  ADDING RECORDS FROM TEXTBOX TO DATABASE
    17.     With objRs
    18.  
    19.         .AddNew
    20.  
    21.         '///// ADD ID TO DATABASE
    22.         gID = generateID()
    23.         'MsgBox "this" & gID
    24.         .Fields!c_id = gID
    25.  
    26.         '//// ADD ID to Text box
    27.         'frmIntro.txtCPID.Text = checkstr(.Fields!c_id)
    28.         frmIntro.txtGlobalID.Text = checkstr(.Fields!c_id)
    29.         GlobalID = checkstr(.Fields!c_id)
    30.  
    31.         .Update
    32.     End With
    33.  
    34.     objRs.Close
    35.     Set objRs = Nothing
    36.  
    37.     Call CloseConnection(objConn)
    He who never made a mistake never made a discovery?

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: trying to set default properties with ALTER TABLE help?

    Its always helpful to post the error information...

    Remove the DefaultDir portion of the connection string, it is not a valid setting in OLEDB...

    VB Code:
    1. AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    2.                  "Data Source=" & App.Path & "\Westfield.mdb;"

  7. #7

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: trying to set default properties with ALTER TABLE help?

    Ok, befor I change all my data connections (I will need some help with this, because I have always used the ODBC provider). I need to know if switching to this new OLEDB is:

    1. is it going to do what I want and,
    2. will I have any problems updating my app on the clients pc.
    3. Is there any other way to modify the table structure using the ODBC provider?
    He who never made a mistake never made a discovery?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width