Results 1 to 7 of 7
  1. #1
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618

    Column or field width on sub form.

    We always have had frustrating challenges with this one. Whether in Design view or Lay out view. "Sometimes" it work sometimes not. Using the mouse to drag the width of fields on the sub form. Exit the form and when returning the fields are the wrong size as it was before. Searching the internet I found many who needed help with this. I found the code from someone as in image 1. Image 2 shows the error with that. Someone said that it worked when he created his form and subform with "form wizzard", didn't work for me, if I did everything right.

    Ruben sometimes fiddle with freeze field and save it and we almost always come right, but not me today. Do you see something in the error message or teach me the way.



    Click image for larger version. 

Name:	Columnwidth001.png 
Views:	15 
Size:	40.4 KB 
ID:	42143Click image for larger version. 

Name:	Columnwidth002.png 
Views:	15 
Size:	27.6 KB 
ID:	42144

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    i think the 2nd param, is not a string, or the 3rd. Null maybe?
    The 1st param IS a string.
    is 2nd param a subform?

    make sure theres no nulls.

  3. #3
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Hi Ranman. Eish, these things increase arthritis. I lied a little, saying recreating my form and sub form in "Form Wizard". Yesterday I only recreated the sub form. During the past hour I recreated both through "Form wizard" . The prove is in my image below. When I was half way I made the first field very narrow by dragging with the mouse. I closed the form, when reopened it was still narrow, great! When finished I tested again and then it didn't work! I do not know what I did to change the result when I was half way to when I was finished.

    I will try to make the VBA work, since where I got the advice from, the person said it works. I am not sure what you are telling me. As on the image my main form is named f02Payment, subform is f02PaymentSub. I will change the name in the properties to sf02Paymentsub, and test both. The control or field that I test the width issue on has a name txt_LdgaccID. The control is bounded to a field named LdgAcc_ID007. Where could there be nulls? I copied the suggested VBA from another forum, normally it works, I assume no problem with the zero. The current error is from the Open event. I am not sure if on the close event the ctrl.Columnwidth = 2 is correct?
    Click image for larger version. 

Name:	Columnwidth003.png 
Views:	15 
Size:	25.8 KB 
ID:	42147

  4. #4
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    I found something. Under the event form_Current, we have the VBA below. When not there, then the field widths can be set, when it is there it doesnt keep the field widths. Our Payment form works in a way that in Batch payments for Salaries and Wages, the account that gets debited is "Salary Control" or "Wage Control". We still want the user to select the employees name. When a creditor is paid, either one at a time or in a batch, a creditor has a "Sub ledger account number". Employees do not have "Sub Ledger account numbers", unless they have a loan with the business or trade with the business. The code below changes the visibility of fields as needed. I am working at it to find exactly why this code prevent the fields to keep the width.
    Click image for larger version. 

Name:	Columnwidth004.png 
Views:	13 
Size:	43.1 KB 
ID:	42148

  5. #5
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    More tests clearly proved that the VBA above got Access not to keep the field widths. My experience tells of all kinds of challenges with the event "Form_Current". My guess it is the first If statement, I will test more. I would like to keep this function in our system but also want to be able to set field widths and see it stay that way. A person on another forum tells about users being unhappy to think that he battles to fix the setting of this problem.

  6. #6
    Perfac's Avatar
    Perfac is offline Expert
    Windows 10 Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    This was an interesting lesson I learnt today. I "cut" the first If statement, removing it from the event "Form_Current". I pasted it to two other controls after update event and all is fine now. I can set the field widths, exit and on returning, they are the way I set it. And my function works. Great!

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Please have a look at the module attached, I have used it for many years with no problems to keep the custom width and order of columns in datasheet forms and subforms. The nice thing is that it preserves them on individual machines so when I deploy a new version of the front-end it will keep the selections for that particular user.
    To use it you just need to follow the example at the bottom of the module.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 5
    Last Post: 03-09-2020, 10:10 AM
  2. Replies: 3
    Last Post: 04-10-2015, 02:35 PM
  3. adjust column width in datasheet form
    By Bospeentje in forum Forms
    Replies: 3
    Last Post: 09-15-2014, 10:13 AM
  4. Replies: 1
    Last Post: 04-10-2012, 12:34 PM
  5. Replies: 0
    Last Post: 12-25-2008, 10:05 AM

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