Global Function

J

JamesJ

I'm using the following code to set the Datasheet Font on a Split
Form using AC 2007.

Private Sub Form_Open(Cancel As Integer)

Me.DatasheetFontName = "Arial"

End Sub

I would like to use a global function so I might call the same function from
all
my forms, but I haven't had much luck.

I tried the following:

Public Function SetDataSheetFont()

Dim frm As Form
Set frm = Screen.ActiveForm
frm.DatasheetFontName = "Arial"

End Function

I get no errors but nothing happens when calling this in the OnOpen of a
form.

Any help will be appreciated,
James
 
A

Albert D. Kallal

In many cases you *can* use screen.ActiveForm

However, if the focus changes, (due to a user mouse click to another form,
then your code would not be reliable, and grab the wrong screen.

The simple solution is to *pass* the form to the code.


Private Sub Form_Open(Cancel As Integer)

Call SetDatasheetFont(me)

End Sub

Public Function SetDataSheetFont(frm as form)

frm.DatasheetFontName = "Arial"

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top