PDA

View Full Version : Solved: Caption of page from multiple page



white_flag
04-14-2010, 07:04 AM
hello :) this is an part of the code from multiple page :


If InStr(sTemp, "page" & i) Then
Controls("Page" & i).Caption
End If

I receive thsi error: Could not find the specified object
Question: how can i initialized correct Caption for an page from multiple page.

thx

lucas
04-14-2010, 09:45 AM
Post your document white flag, please.

I for one can't see how you're identifying your label controls.....


Also, if it's not too much trouble, could you describe what you are trying to do?

For instance, you have a label on each page of the multipage and you want it to reflect which page is active? I can't understand your need from your brief post.

fumei
04-14-2010, 09:57 AM
A page is a property of a Multipage, as in:
MultiPage1.Pages(i).Caption


See Help.

fumei
04-14-2010, 09:59 AM
Note that the MultiPage Pages collection is zero-based.

white_flag
04-14-2010, 10:02 AM
ok ..sorry for the small description

thsi code populate date for user form via an text file:


Private Sub meniu()
Dim i As Long, fs, s, ts, f, j, k
Dim InputData, T
Dim nFile As Integer
Dim sTemp As String
Dim nEqualsSignPos As Integer
'ia text dintr-un fisier de la o anumita locatzie
nFile = FreeFile()
Set fs = CreateObject("Scripting.FileSystemObject")
For j = 1 To 3
If Controls("OptionButton" & j) = True Then
Set f = fs.GetFile(ActiveDocument.Path & "\text." & j)
Open ActiveDocument.Path & "\text." & j For Input As #nFile
Do While Not EOF(nFile)
Input #nFile, sTemp
For i = 11 To 12
If Len(sTemp) > 0 Then
nEqualsSignPos = InStr(sTemp, "=")
nEqualsSignPos = nEqualsSignPos + 1
If InStr(sTemp, "lab" & i) Then
Controls("Label" & i).Caption = Mid(sTemp, nEqualsSignPos)
End If
If InStr(sTemp, "frame" & i) Then
Controls("Frame" & i).Caption = Mid(sTemp, nEqualsSignPos)
End If
If InStr(sTemp, "comand" & i) Then
Controls("CommandButton" & i).Caption = Mid(sTemp, nEqualsSignPos)
End If
' If InStr(sTemp, "pag"&i) Then
' Controls("Page" &i).Caption = Mid(sTemp, nEqualsSignPos) 'error object ..
' End If
If InStr(sTemp, "check" & i) Then
Controls("CheckBox" & i).Caption = Mid(sTemp, nEqualsSignPos)
End If
End If
Next
Loop
Close nFile
End If
Next
Set ts = f.OpenAsTextStream(1)
Data = Split(ts.Readall, "|")
'populare combobx
For k = 11 To 27
InputData = Split(Data(k - 1), Chr(13))
For Each T In InputData
If Len(T) > 0 Then Me.Controls("ComboBox" & i).AddItem Application.Substitute(T, Chr(10), "") 'error what is substitute for word
Next
Next
End Sub


but I have two errors.
one: to initialization of page from multiple page
two: Aplication.substitution

white_flag
04-14-2010, 10:12 AM
thx, Fumei

If InStr(sTemp, "pag" & i) Then
MultiPage1("Page" & i).Caption = Mid(sTemp, nEqualsSignPos)
End If

for the second error ..can you help me?

fumei
04-14-2010, 10:33 AM
Application.Substitute is ONLY for VBA version prior to 2000. If you are using later, try Replace.

BTW: it is ALWAYS a good thing to state what version you are asking about.

I believe SUBSTITUE is still valid for a Excel cell formula.

I am not sure exactly what you are doing, but I have to say it looks a bit strange to me.

Oh, and please try to use the underscore character ( _ ) when posting code. Otherwise the code window goes all wonky.

For Each T In InputData
If Len(T) > 0 Then Me.Controls("ComboBox" & i).AddItem _
Application.Substitute(T, Chr(10), "") 'error what is substitute for word
Next

white_flag
04-14-2010, 11:41 AM
correct it is from excel. can be "translate" this code for word?
please look in attachment

fumei
04-14-2010, 12:07 PM
Wrong syntax.

Me.Controls("ComboBox" & i).AddItem _
Replace(t, Chr(10), "")
It is not Application.Replace.

Replace is a VBA function, not a method of the Application.

BTW: I would use .ListIndex to show a starting value in the combobox. I do not like seeing "empty" comboboxes.
Option Explicit
Dim Data

Private Sub UserForm_Initialize()
Dim i As Long, fs, s, ts, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("C:\zzz\Test\TestWhite\data.1")
Set ts = f.OpenAsTextStream(1)
Data = Split(ts.Readall, "|")
For i = 1 To 5
Populate i
Next
Call ShowSomething
End Sub

Sub Populate(i As Long)
Dim InputData, t
InputData = Split(Data(i - 1), Chr(13))
For Each t In InputData
If Len(t) > 0 Then _
Me.Controls("ComboBox" & i).AddItem _
Replace(t, Chr(10), "")
Next

End Sub

Sub ShowSomething()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.ComboBox Then
Me.Controls(ctl.Name).ListIndex = 0
End If
Next
End Sub
Note that I changed the path to Data.1 (crappy name if I may say so) to a valid (for me) path.

white_flag
04-14-2010, 12:43 PM
ok ..I note that and change it (the path to file)

Set f = fs.GetFile(ActiveDocument.Path & "\menu")


thx for initialisation of combos & for help :) have fun