Results 1 to 6 of 6

Thread: Repaint

  1. #1
    Join Date
    Dec 2005
    Posts
    121

    Unanswered: Repaint

    Does the repaint form process perform the on open actions of a form? If not, is there a way without closing and opening the form again to have that event re-run without tying it to the many fields in the form?

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    As far as I know (and what I use the repaint command for), the repaint command will "re-draw so to speak" the form (without querying the records). For example, I use it to for my 'Progress Bar' form to show the new width of the progress bar. Or I use it to 're-fire' Conditional Formatting on the form. Sometimes I may also use the "Refresh" command (but I believe this works for forms with recordsets and doesn't work on my Progress Bar form since it's not bound to a recordset and I reference it from a function.) I use the Refresh command within the form itself as it's problematic trying to Refresh a different form.

    Note that this will work:
    Forms!MyProgressBarForm.repaint
    Forms!MyProgressBarForm.requery

    While this won't work:
    Forms!MyProgressBarForm.Refresh

    If you have an event you want to re-run on the form, you can always make it a function within the form (or put the function in a module) and then call that function (Note: in a module, you'd reference the fields on the form as such: Forms!MyFormName!MyFieldName). I do this often. Either that or make the event in the form Public versus Private and then call it (ie. Fieldx_AfterUpdate()). I try to avoid making Private events as Public in a form though since it's easy to end up with duplicated Public event names within your mdb application (and that's not good!)

    I'm not sure I understand your question but I hope this helps.
    Last edited by pkstormy; 01-08-10 at 21:41.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Dec 2005
    Posts
    121
    It is actually a form with 35 fields for carton numbers to be added to. The record is already created as a pallet id number and this form allows the user to scan 35 different 20 digit carton numbers along with 2 seals onto the form. When the form opens, all fields are disabled and it looks for the first carton number field that is empy and enables that field along with the 2 seal fields. When a carton number, seal 1 and seal 2 have been scanned. the on change property for seal 2 disables those 3 fields.

    Due to edits and deletions, I can't just simply tell it drop down 1 postion and enable the next carton and seal fields. It may need to move upward if a carton was removed to use that open spot as the next available position. The only way I have found to do this is to close the form after the seal 2 has been scanned and then immediatly re-open it. It then finds the next carton number field that is null and enables that position (3 fields).

    I was hoping to get away from closing and reopening the form after every carton scanned. Maybe there is a way to initiate the OnOpen sub with out actually closing and opening the form? Thru a backdoor command of some kind?

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    What I've done in these situations is move the OnOpen code into a Function in the form. I then call the function in the OnOpen event (or from any other event where I want the function to fire the code.) I may have to throw in a me.repaint, me.requery or me.myFieldName.requery command (or setting fields to null or re-calculate a field) in the function to make it work but it pays off without having to re-open the form. I also often do this when I'm using the timer event of the form and want to call the function interrupting the timer event so to speak.

    ex:
    Private Sub OnOpen()
    Call CalcValues
    end sub

    Private Sub FieldX_AfterUpdate()
    Call CalcValues
    End sub

    Function CalcValues()
    if isnull(me!FieldName) then exit function
    me.fieldname.defaultvalue = me!fieldname + 1 (ie. increment counter field)
    me.requery
    docmd.gotorecord,,acnewrec
    me!someotherfieldname = me!fieldname + 1 (ie. increment some other counter field/write record)
    me.datafieldname.setfocus
    End Function


    I'm not sure if this works in your situation. I kind of understand.
    Last edited by pkstormy; 01-08-10 at 22:48.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    It gets tricky when you're dealing with blank values when the form opens versus populated values on the form after the form opens (ie. bound/unbound fields). I try to make the function work regardless if the form is opening or it's already open.

    Sometimes I will also dimension variables (within the sub such as Dim myCounterVariableName as variant under the Option Explicit) as counters and using them with the me.controls("FielName" & myCounterVariableName).value = somevariable type coding, incrementing myCounterVariableName or somevariable as needed based upon an event or function. This works nicely when you have a lot of unbound fields named the same but sequentially (ie. CalDate1, CalDate2, CalDate3) and you want to get/write the values to them quickly. You can carry this a step further and then write looping type code to loop through all the fields and do things such as set the background/foreground color or manipulate values in all the fields, or set conditions when it comes across a specific value. This type of coding usually works best on single forms versus continuous forms.
    Last edited by pkstormy; 01-08-10 at 23:05.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Dec 2005
    Posts
    121
    Actually the Function worked out just fine. I had not used that method until today, but it served the purpose just fine. Thanks for the direction!

Posting Permissions

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