SetMarginsToDefault module

G

Guest

I have created the above module, using code from Microsoft, in Access 2003.
This is it:

Type str_PRTMIP
strRGB As String
End Type

Type type_PRTMIP
xLeftMargin As Long
yTopMargin As Long
xRightMargin As Long
yBotMargin As Long
fDataOnly As Long
xWidth As Long
yHeight As Long
fDefaultSize As Long
cxColumns As Long
yColumnSpacing As Long
xRowSpacing As Long
rItemLayout As Long
fFastPrint As Long
fDatasheet As Long
End Type

Sub SetMarginsToDefault(strName As String)
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
DoCmd.OpenReport strName, acViewDesign
Set rpt = Reports(strName)
PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
' set margins
PM.xLeftMargin = 1 * 1146
PM.yTopMargin = 1 * 1146
PM.xRightMargin = 1 * 850
PM.yBotMargin = 1 * 850
LSet PrtMipString = PM
rpt.PrtMip = PrtMipString.strRGB
DoCmd.Save
End Sub


When I compile it, I am getting an error "Type Mismatch" at the following
line.

LSet PM = PrtMipString

I've used this code previously and it has worked fine. Can anyone shed some
light on why I'm getting the compile error.
 
G

Guest

Hi Fiona,

Try changing this:

Type str_PRTMIP
strRGB As String
End Type

to this:

Type str_PRTMIP
strRGB As String * 28
End Type


I was able to reproduce your compile error without the * 28 part. I have
a module with the same exact code, but in this case, I seem to have failed to
document where I got it from (I'm usually pretty good about including a
comment with a hyperlink to the original source). If you happen to have that
info. handy, please pass it on.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
G

Guest

Hi Tom

That has now compiled - thanks.
I can't remember where I first got the code, but have found it very useful.
I just keep copying it from other databases now.

Cheers
 
G

Guest

Hey Tom,

Well the code compiled OK, but now when I run it I am getting an error
"The expression OnClick you entered as the event property setting produced
the following error: A problem occurred while Events was communicating with
the OLE Server or ActiveX Control.

The onclick code is..

Private Sub cmdOK_Click()

Call SetMarginsToDefault("rptOutageSummary")
DoCmd.OpenReport "rptOutageSummary", acViewPreview
Exit Sub

End Sub

Crickey, I can't understand why I'm having so much trouble with it. I've
used it problem free so many times in the past. I am at a different
organisation though, trying to run it for the first time.
 
G

Guest

Hi Fiona,

I just created a quicky test database, using your version of the code, and
it works fine for me. I can send you a zipped copy of this test file, if
you'd like.

I did find this KB article that might apply in your case:

You receive an error message when you start Visual Basic for Applications
code in an Access database
http://support.microsoft.com/kb/907337

Perhaps that holds the key to this dilemma.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
G

Guest

PS. I don't recommend changing the language settings, as indicated in Method
1 of the KB article. You might be able to fix this situation by copying your
code to a text file first, save the text file, and then delete the module.
Then create a new module and paste the code back in from the text file. That
way, the module will have been created with the same Unicode settings.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
 
G

Guest

Hi Tom

I will try what you suggested.

Thanks for your help, will let you know how I go, tho I'll be out of the
office for the next day or two.

Fiona
 
G

Guest

Hi Tom

All working perfectly now, though I can't say what was wrong. I did what you
suggested and create a whole new module and it worked!

You are a legend, thanks Tom.
 
G

Guest

Hi Fiona,
All working perfectly now, though I can't say what was wrong. I did what you
suggested and create a whole new module and it worked!

Previously, you had written:
"I am at a different organisation though, trying to run it for the first
time."

I suspect that the PC you are using today has a different non-Unicode
language setting versus the PC that you used at your previous organization.
If this is the case, then I would expect a similar error message if you
imported any other module from a saved database that was created at the
previous location.
You are a legend, thanks Tom.

Blush!

Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

John W. Vinson

You are a legend, thanks Tom.

Hate to disabuse you, but Tom's quite real, not a legend... and just as
impressive as his newsgroup posts suggest!

John W. Vinson [MVP]
 
D

dbahooker

hey if you want more help from Tom, you could probably call him

I found his address and phone number at zabbasearch.com


TOM G WICKERATH
15851 12TH PL
BELLEVUE, WA 98008 (425) 562-8913
 

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

Similar Threads

Setting Print Margins 1

Top