Dynamic Form properites

IR_Moon

Registered User.
Local time
Tomorrow, 05:01
Joined
Jun 6, 2006
Messages
20
Hi there!

I have an Access application that displays a different colour on it's forms depending on the selected client. It's kind of somewhere between trying to make it prettiful and trying to make it functional by alerting users IMMEDIATELY to which client they are entering/viewing data for.

The database has about 12 different forms in it, and I've put this in as code on EVERY page:

Code:
    [COLOR="Green"]' add background picture[/COLOR]
    Dim BackPicName As String
    BackPicName = Forms![frmOpen]![cboPickClient].Column(6) & "back_blk.bmp"
    [COLOR="#008000"]'only if it exists...[/COLOR]
    If Dir(BackPicName) <> vbNullString Then
        Me.Picture = Forms![frmOpen]![cboPickClient].Column(6) & "back_blk.bmp"
    Else 'set no background picture
        Me.Picture = vbNullString
    End If

Which works fine... I just duplicated this code on every form on open... The problem being I'm now looking at adding other features to this function but don't really fancy duplicating the updates 12 times for 12 forms.

I've attempted to creat a subroutine in a module that the form can refer to on open and am trying to use the above code in that module (which I'm sure is where I'm going wrong and probably shows me to be a total n00b! I've not used modules much yet!)

I get a compile error as follows:

compileerror.jpg


So basically what I'm after is a method for re-using the same bit of code across multiple forms... Any help offered would be greatly received!
 
In a standard module you can't use the keyword ME as ME is limited in scope to the module of the actual form that the code is on.

Change your code so that you pass the form name to the function that you have in the standard module and then use that in place of Me.

For example -

Your code above with the changes:
Code:
Public Function SetBackground(strFormName As String)
   Dim BackPicName As String
    BackPicName = Forms![frmOpen]![cboPickClient].Column(6) & "back_blk.bmp"
    'only if it exists...
    If Dir(BackPicName) <> vbNullString Then
        Forms(strFormName).Picture = Forms![frmOpen]![cboPickClient].Column(6) & "back_blk.bmp"
    Else 'set no background picture
        Forms(strFormName).Picture = vbNullString
    End If
and in each of your forms you only need to add this line in whatever event you want (probably the On Load)
Code:
SetBackground Me.Name
 
Cheers Bob! You and GHudson both have a knack of making the incredibly frustrating into the painfully obvious without belittling the user! Cheers muchly... it's the response I was looking for... and soooo much easier than what I Was trying to do!
 

Users who are viewing this thread

Back
Top Bottom