msgbox customise

G

Guest

Hi all,

Having a procedure to display custom errormessages I would like to place
this within a function, so I do not have write all vb over and over again.
So within procedure of the form I declared strMessage, strBoxType,
strBoxHeader a string.
Using this within the same procedure it functions but I want to call a
function like
goNextRecord having an errorstatement. fe
button1_click()
strBoxType = vbCritical
strBoxHeader = "Box Header"
strMessage = "ERROR"

GoNextRecord
end sub
Function GoNextRecord()
On Error GoTo Err_GoNextRecord
DoCmd.GoToRecord , , acNext
Exit Function
Err_GoNextRecord:
MsgBox strMessage, strBoxType, strBoxHeader
Exit Function
End Function

so this function can handle the routine for all forms within my db.
unfortunately the function does not display the string as they are
(according the debugger) empty.
Can someone please help me out?
Greetings,
Harry
 
G

Guest

Where did you declared this varables:
strBoxType , strBoxHeader , strMessage

They need to be declared in a module as global

Global strBoxHeader As String

etc.
 
G

Guest

Hi Ofer,
Within de code of the form and within the module I declared
Option Compare Database
Dim ContactID As String
Dim stDocName As String
Dim stLinkCriteria As String
Dim strMessage As String
Dim strBoxType As String
Dim strBoxHeader As String
 
G

Guest

Don't declare it under the form, just in the module.
Change the Dim to Global

Global strMessage As String
Global strBoxType As variant
Global strBoxHeader As String
 
G

Guest

Hi Ofer,
Thanks for the fast reply.
Unfortunately it doesn't work.
I have changed the module as suggested, and removed the dim xx as string
from the form.
the procedure of the form is like

Private Sub NextVisit_Click()
strBoxType = vbCritical
strBoxHeader = "BoxHeader"
strMessage = "ERROR"
GoNextRecord
End Sub
(changing the line to GoNextRecord strBoxMessage,strBoxType,strBoxHeader is
also giving an error)
Within my code I receive the error 13 Type Mismatch

the msgbox string within the module I use is;
MsgBox strMessage, strBoxType, strBoxHeader

As I declare the values of the three strings within the module the
messagebox shows just fine.

Greetings,

Harry
 
G

Guest

Sorry for the delay,

What exactly doesn't work?
Can you post the declaration of the variables and the function?
 
G

Guest

Hi Ofer,
Thanks a lot for your help.
Within a private sub I had defined (how stupid) a dim strBoxHeader as string
and so on.
Just removing the defenition and all works.

my apoligies for this and hope you did not spend too much time in helping me
out.

greetings,
Harry
 

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