Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27

    Unanswered: Re-sizing table field width (in VBA only)

    i have a form that has a table in a subform, is there a way i can have it so when the form is opened the tables field width are pre-set?

    i need to set this everytime the form is opened because the table is constantly being droped and created again using DoCmd.RunSQL...

  2. #2
    Join Date
    Jul 2003
    Posts
    38
    Sorry, your question isn't absolutely clear for me. Do you want to set up the size of your control (textbox or whatever) in your form or the size of the fields in the tables?

    For resizing the controls in the form (what i guess you want to do) use:

    dim frm as form
    dim ctrl as control

    set frm=forms(FORMNAME)
    set ctrl=frm.controls(CONTROLNAME)
    ctrl.width=X

    If you want to resize within the table, you can't do this on a form basing on the table. You have ro close it first and then work on the tabledef object.

  3. #3
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27

    it's resizing the table columns width in VBA

    It's the actual columns width of a table....

    i use....
    AuthorisationForm.SourceObject = "Table.AuthorisationSection_EPRNo_" & EPRNo & ""

    ....to make an object on a form into a table (depending on the EPRNo variable), but i want to set the width of the columns within that table?

    can it be done?

    cheers....

    phil

  4. #4
    Join Date
    Jul 2003
    Posts
    38
    Yes, look for the tabledef:

    set db = currentdb
    set td = db.tabledefs(yourtable)

    td.fields(yourfield).width=2345

  5. #5
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27
    Sorry,

    i'm totally new to this could you give me an example of the table def....?

    cheers
    phil

  6. #6
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27
    Private Sub Form_Open(Cancel As Integer)
    ' sets an unbound object as the table StaffDetails table
    tableOnForm.SourceObject = "Table.StaffDetails"

    Set db = CurrentDb
    Set td = db.tabledefs("StaffDetails")
    td.Fields("StaffID").Width = 2345

    End Sub


    i added your snippet, but it says ....

    RunTime error438
    object doesn't support this property or method??


    any suggestions??

  7. #7
    Join Date
    Jul 2003
    Posts
    38
    Hmm, my fault - the tabledef object has a property called properties where you can define the width. Normally you have to create this property first, so check the helpfile for td.fields(x).createproperty(width)

Posting Permissions

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