Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Design Mod to Form by VBA Code ? (Access 2003)

    G'day All

    I have a piece of code in a module separate from my forms which updates various aspects of a form. Updates include re-querying listboxes, hiding and unhiding controls depending on user selected system options, coloring the background of text boxes if there is data missing from fields in the record that should not be.
    This routine actually updates all forms in my database. It takes the name of the form as a paramenter and updates the appropriate form. I originally did this so that I could refresh list boxes when a user changes records in another form. So user has FormA which allows him to choose a staff member from a listbox. User can double click on the listbox and FormA minimises and FormB (Staff Update Form) opens where the user edits/deletes/adds staff members. When he closes this form, the FormUpdate routine runs and the calling form has it's listboxes refreshed. A copy of the routine is below.

    Problem is, I am now striking an errorin Access03 where this routine seems to be altering the design of the form. I have a Next Record button which scrolls through the records in the form with a DoCmd.GoToRecord , , acNext

    I'm getting an error as this line executes: Run-time error 2499 : You can't use the GoToRecord action or method on an object in Design View. This error generates on my second click of the Next Record button. The first click scrolls to record number 2, calls the formupdate routine. The second click fails with this error.

    Any ideas?

    Regards Ken
    Attached Files Attached Files

  2. #2
    New Lounger
    Join Date
    Jan 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    This is all I can find for now. I will look more tomorrow.

    http://office.microsoft.com/assistance/pre...,FX,ES,EP,DC,XT

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    Why are you looping through all the forms to find the one whose name was passed? You can simply set the form object to point to the specified form.

    I'm also not clear on why you're trying to setfocus on a form that doesn't have the focus in the first place. The more usual place to call a routine like this would be in the Close event of the form where you're changing values, just before focus passes back to the other form. I assume you aren't doing it that way because you have some sort of arrangement that keeps both forms loaded and allows the user to switch back and forth between them. If that is the situation, maintaining it is going to be difficult. Is the application multiuser? If so, you have a bigger problem. Design changes can only be made in Access 2000 and later if a user has exclusive access to the application.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    G'day Charlotte - thanks for the reply.

    I loop through probably because this routine is an inherited one from an older application when my programming knowledge was not as good as my lateral thinking. I originally passed a pointer to the form but for some reason at some point this gave me problems I didn't understand and so I resorted passing text and looping through looking for the calling form.

    This routine is called within the form on the current event, so that as the records cycle through the contents of the form adapt to match the data. Thus if some fields are missing contents, those controls have colored backgrounds. It's also called if a record is deleted, so that the list boxes are updated. And if a record is added - same requirement. I know conglomerating them like this is something of a brute force method, probably need to rethink it. It's also called from other forms, when they are closed, and the form that is passed to the update routine is the form that called the form that is closing.

    So basically - hiding and unhiding controls, changing background color/transparency of controls is design changes on the fly? Particulary with Multi User? Any other way to change the display of a form based on the contents of the record?

    Ken

  5. #5
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    Oh - setting the focus.
    I keep running into trouble with disabling and changing controls that have the focus. So I set the focus somewhere safe so it doesn't happen. I haven't managed to work out how to test if a certain control on a form has the focus. How do you check for this?
    Ken

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    There are several ways. The simplest is to try to set the focus to it and trap the error that occurs if you can't.
    Charlotte

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    No, hiding controls and changing backcolors isn't necessarily a design change ... unless you make it in design view. If you are calling this routine from the form being changed, you should be able to pass Me as the form object and then handle it in your routine directly.

    If all you're doing is toggling visibility, you shouldn't be running into problems. Since you refer to the error " Run-time error 2499 : You can't use the GoToRecord action or method on an object in Design View.", I have to assume that something is kicking it into design view.
    Charlotte

  8. #8
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    Right ... but is there a way of :
    (a) Testing if a particular control has the focus; and/or
    ([img]/forums/images/smilies/cool.gif[/img] Finding out which particular control has the focus;
    without changing the focus?
    I vaguely recall playing with a screen object, but wasn't successful.
    Ken

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    A form has a property ActiveControl; this is an object of type Control. If you want to obtain its name, use ActiveControl.Name. The Screen object also has a property ActiveControl. The difference is best explained in an example:

    You have to forms open: frmA, with the focus on control ctlA, and frmB, with the focus on control ctlB. At the moment, frmA is the active form.
    Screen.ActiveControl.Name returns "ctlA", since this is the active control on the active form.
    Forms!frmA.ActiveControl.Name and Screen.ActiveForm.ActiveControl.Name also return "ctlA".
    Forms!frmB.ActiveControl.Name returns "ctlB", since this is the active control on frmB, even if frmB is not the active form at the moment.

  10. #10
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    Ok. So let's say I have a control on frmA called TaskID. I want to hide TaskID for some reason, and want to check first if this control has the focus. So I would use:

    If Forms!frmA.ActiveControl.Name = [TaskID].Name Then

    Correct?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Design Mod to Form by VBA Code ? (Access 2003)

    1. If you run this code from FrmA itself, you can use Me.ActiveControl.Name, if you call it from another form, you must use Forms!frmA.ActiveControl.Name.
    2. Instead of [TaskID].Name, use "TaskID".

    So if you run the code from frmA itself, use

    If Me.ActiveControl.Name = "TaskID" Then

Posting Permissions

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