Text String... (1 Viewer)

Mike Leigh

Registered User.
Local time
Today, 10:38
Joined
Feb 5, 2001
Messages
11
Hi,

I have a requirement to open a msgbox and display a text string when a record will be duplicated.

This is all done in VBA and it all works.

However I want to be able to reuse the code for other forms and the problem is this. I have a table called tbl_error_message in this there are 2 fields msgid and msgtext.
msgid = 100
msgtext = %1 is allready included for %2
or in english XYZ is allready included for company

%1 and %2 are 2 variables that I store in a text string and I need some code to first alter the helptext string by replacing %1 with whatever is in my variable for %1 and the same for %2.

at the moment my (msgbox !msgtext) code will display whatever is stored in the msgtext field for msgid 100.

Has anyone ever had to do this sort of thing before ?

Thanks in advance
 

Atomic Shrimp

Humanoid lifeform
Local time
Today, 10:38
Joined
Jun 16, 2000
Messages
1,954
Should be as simple as:

msgtext = %1 & " is already included for " & %2

Mike
 

Mike Leigh

Registered User.
Local time
Today, 10:38
Joined
Feb 5, 2001
Messages
11
thanks for the reply. However it is not as simple as that - I wish it was :)

If I do what you suggest the message box simply takes it as a string (which is what it is supposed to do I think).

I have also tried having the following in the field

" & %1 & "message

Access 97 seems to ignore whatever is in the string and just plonk it in a message box.

My code for the msgbox is very simple

msgbox !msgtext

It seems to surround whatever is in the field !msgtext with " at the beginning and " at the end. So no matter what I type in there is just displayed as a message.

Any other ideas

Thanks in advance
 

Mike Leigh

Registered User.
Local time
Today, 10:38
Joined
Feb 5, 2001
Messages
11
just a note on the previous post...

If a declare %1 and %2 as variables and then set them to ABC and DEF respectively in Mike Gurmans example I would receive the correct result. However I want to have %1 and %2 in the msgtext and let vb include this alltogether for me. This way I can use the form many times to accomplish the same tasks. I envisage using this style of form at least 17 times. So it will make life easier in code.

[This message has been edited by Mike Leigh (edited 07-24-2001).]
 

Axis

Registered User.
Local time
Today, 10:38
Joined
Feb 3, 2000
Messages
74
Try using something other than % as the first character of the variables. Access may read % as a special character and not process it.

msgtext = str1 & " is already included for " & str2
MsgBox msgtext
 

KDg

Registered User.
Local time
Today, 10:38
Joined
Oct 28, 1999
Messages
181
If i've read the above right then you have a field in your db that contains "%1 is included for %2". If that's the case you'll need to write a string parser to strip %1 and %2 and replace them with the relevant wording. Otherwise they are just part of a string and won't be differentiated in any way.
It's rather like having
Dim strOne as string
dim strTwo as string

strOne="Hello"
strTwo="strOne & Mike"

I think the answer is as you suggested, you need to create a function that will accept a finding and replacing string
eg Function ReplaceBase(strToFind as string, strToReplaceWith as String) etc etc

HTH

Drew
 

Mike Leigh

Registered User.
Local time
Today, 10:38
Joined
Feb 5, 2001
Messages
11
Axis - your right access does not accept %1 as avariable - however in a string it works. I have changed %1 to V1 and %2 to V2.

KDg - that is exactly what I am attempting to do. I have no idea how to read a text string and look for the instance of V1 and replace with another value and then look for V2 and replace with a value.

The string may or may not contain V1 or V2. So the code will need to check if V1 exists in the string and then replace.

Any ideas

Thanks in advance
 

KDg

Registered User.
Local time
Today, 10:38
Joined
Oct 28, 1999
Messages
181
Hi Mike,

i'm not sure that this is exactly what you're after but it may be a start
Code:
Function FindAndReplace(strString As String, strFind As String, strReplacement As String) As String
    ' replace every instance of strFind within strString with strReplacement
    Dim x As Integer 'place holder for strFind
    
    x = InStr(1, strString, strFind)
    Do While x > 0
        strString = Left(strString, x - 1) & strReplacement & Mid(strString, x + Len(strFind), Len(strString))
        x = InStr(1, strString, strFind)
    Loop
    FindAndReplace = strString
End Function

Sub callfinder()
    Dim strBaseString As String
    Dim strTheVar As String
    Dim strTheVar2 As String
    strBaseString = "V1 hello people V2"
    strTheVar = "wol"
    strTheVar2 = "WOOOOO"
    MsgBox FindAndReplace(strBaseString, "V2", strTheVar)
    MsgBox FindAndReplace(strBaseString, "V1", strTheVar2)
End Sub

It works okay with % too but it's probably best to avoid them. I'm pretty bad at commenting code so if you want an explanation please post back

HTH

Drew
 

Mike Leigh

Registered User.
Local time
Today, 10:38
Joined
Feb 5, 2001
Messages
11
Thanks Drew I will try this and let youse know how I get on
 

DALeffler

Registered Perpetrator
Local time
Today, 03:38
Joined
Dec 5, 2000
Messages
263
Why are you trying to search for V1 or V2 within the string? This looks like a message where you know the two variables would go in front of and behind the string (because of msgid = 100). Have you tried:

Dim V1, V2 as String
V1 = "Some String "
V2 = " Different String"

MsgBox V1 & me!msgtext & V2

Doug.
 

Mike Leigh

Registered User.
Local time
Today, 10:38
Joined
Feb 5, 2001
Messages
11
Hi there.

Yes I have tried the way you suggest and it does work. However I want to be able to do everthing in code so I can reuse the form. I am using msgid = 100 in a global error table which can also accept user defined variables. e.g. where V1 or %1 is pull this from somewhere else. This will save me time in recoding in the future.

Also in the example msgid 100 does have V1 and V2 at either end of the string. msgid 110 may have the following [V1 some text V2 some more text] without the []

This is another reason why I have to read the string

Has this helped to show why I am confusing everyone with a simple litlle msgbox :)

[This message has been edited by Mike Leigh (edited 07-25-2001).]
 

Users who are viewing this thread

Top Bottom