borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (SQL server configuration)Next Topic (Master/Detail form) New Topic New Poll Post Reply
AndreaVB Forum : Database : ADOX Table Creation - Access Properties
Poster Message
ezimmerman
Level: Guest


icon ADOX Table Creation - Access Properties  Archived to Disk

Does anyone know if it is possible to set Microsoft Access Layout properties, such as column widths, row heights, etc. through ADO or ADOX, when creating a new table??

If so, how? ... I feel like I've been searching forever for it.
Otherwise, is it programmable at all?
Thanks Much,

Eric

11-06-2002 at 08:51 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: ADOX Table Creation - Access Properties  Archived to Disk

I modified the original post...
Private Sub ChangeWidth()
    On Error Resume Next
    
    Dim dbs As DAO.Database
    
    Set dbs = CurrentDb

' Index is the table name, fields("Name") change for whatever field needed
    dbs.TableDefs("Index").Fields("Name").Properties("ColumnWidth").Value = 5000
' Sometimes caused errors without the following
    dbs.TableDefs("Index").CreateProperty "RowHeight", dbInteger, 5
    dbs.TableDefs("Index").Properties("RowHeight").Value = 5000

    Set dbs = Nothing
End Sub

[Edited by JLRodgers on 11-06-2002 at 05:15 PM GMT]

11-06-2002 at 09:42 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ezimmerman
Level: Guest

icon Re: ADOX Table Creation - Access Properties  Archived to Disk

Sweet!.. you're a life saver

You wouldn't happen to know the ADO equivalent to that would you??

Thanks again!

12-06-2002 at 01:41 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: ADOX Table Creation - Access Properties  Archived to Disk

Not sure offhand, if you have Access, you can search in the help (vb editor within access [maybe in the MSDN library too]) for:

RowHeight
ColumnWidth

In the OfficeXP versions there's a link for "Visual Basic" code, that has lists for the DAO and ADO code.

12-06-2002 at 02:25 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ezimmerman
Level: Guest

icon Re: ADOX Table Creation - Access Properties  Archived to Disk

I haven't found the ADO code equivalent yet, but I think it has something to do with the ADO command object...


Ok, the original code that was submitted didn't work quite right, but this is a functional, slightly modified copy.

I am modifying all widths of the fields in the table based on their field name.

On error resume next is bad... use explicit err numbers for resume nexts...

g_fn() is an global array of strings. (filenames)



Private Sub ChangeListWidth(ByVal mode As Integer)
    On Error GoTo errHandler
    
    Dim dbs As DAO.Database
    Dim prpNew As DAO.Property
    Dim strDest$, str_field$
    Dim i%, fieldwidth%
    
    Set dbs = DBEngine.OpenDatabase(g_fn(rDEST)) 'CurrentDb
    
    Select Case mode
        Case rGPLUS: strDest = "Lists"
        Case rVGPLUS: strDest = "ListsVG+"
        Case Else
    End Select

    DoEvents

    For i = 0 To dbs.TableDefs(strDest).Fields.Count - 1
        DoEvents
        str_field = dbs.TableDefs(strDest).Fields(i).Name
        If (str_field = "ID") Then
        ElseIf (InStr(1, str_field, " Val")) Then
            fieldwidth = 300
        Else
            fieldwidth = 1500
        End If
        
        Set prpNew = dbs.CreateProperty("ColumnWidth", dbInteger, 5)
        dbs.TableDefs(strDest).Fields(i).Properties.Append prpNew
        dbs.TableDefs(strDest).Fields(i).Properties("ColumnWidth").Value = fieldwidth
    Next i
        
    Set dbs = Nothing
    Exit Sub
    
errHandler:
    Select Case Err.Number
    Case 3367           'already exists in collection
        Resume Next
    Case Else
    MsgBox Err.Number & " " & Err.Source & Chr(13) & Err.Description, vbCritical
    End Select
    
End Sub


eRiC

13-06-2002 at 01:30 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: ADOX Table Creation - Access Properties  Archived to Disk

The reason for the "resume next" was that the only line that could've caused a problem was the "create property" in the example. That property should already exist, but for some reason it didn't always like running without it. In the event there was another error in the code, then there would've been a problem with the DAO engine, and chances are, you'd never get to run the code anyway.



13-06-2002 at 06:45 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Database : ADOX Table Creation - Access Properties
Previous Topic (SQL server configuration)Next Topic (Master/Detail form) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder