From: FKlusmann on 15 Jan 2010 22:24 Hello and thanks again. I'd like to get several lines of text from a table and display them in forms textboxes. My table is TextTest01 with 3 fields (no PK, no index): sel is text field size: 2 lineNo is number long integer line is text field size 80 My unbound form fTestText01 has 10 textboxes named Line01, Line02 .. To Line10. My code efforts are: Private Sub Form_Open(Cancel As Integer) Dim linecount As Integer ' Line conter (set to 9 for this test) Dim ctr As Integer ' Counter to be incremented Dim varResult As Variant ' will hold the answer Dlookup provides Dim txtboxname As Variant ' the name of form's textbox to be populated Dim selct As String ' A group indicator will come from a table selct = "W" ' W indicates Welcome linecount = 9 ' maximum number of lines to display For ctr = 1 To linecount ' the answer the text the table tbl field match value varResult = DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") ' this finds the correct text. ' where I want this to be displayed txtboxname = ("Line0" & CStr(ctr)) ' dim'd as object gives error 91 ' this holds the correct form textbox names ' Me.Controls("txtboxname").Text ' txtboxname dim'd as string gave error 2465 Tab Tests -(Keep) can't find the field "txtboxname .. Set txtboxname = varResult ' when dim'd as string gives error 424 - object required ' when dim'd as object gives ' when dim'd as variant gives run-time error 13 type mismatch Next ctr End Sub .... I would sure like your help to make this work. Thanks, -- Fred
From: Douglas J. Steele on 16 Jan 2010 15:48 -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "FKlusmann" <u57520(a)uwe> wrote in message news:a22d595a6f2f6(a)uwe... > Hello and thanks again. > I'd like to get several lines of text from a table and display them in > forms > textboxes. > > My table is TextTest01 with 3 fields (no PK, no index): > sel is text field size: 2 > lineNo is number long integer > line is text field size 80 > My unbound form fTestText01 has 10 textboxes named Line01, Line02 .. To > Line10. > > My code efforts are: > Private Sub Form_Open(Cancel As Integer) > Dim linecount As Integer ' Line conter (set to 9 for this test) > Dim ctr As Integer ' Counter to be incremented > Dim varResult As Variant ' will hold the answer Dlookup provides > Dim txtboxname As Variant ' the name of form's textbox to be populated > Dim selct As String ' A group indicator will come from a table > selct = "W" ' W indicates Welcome > linecount = 9 ' maximum number of lines to display > For ctr = 1 To linecount > ' the answer the text the table tbl field match value > varResult = DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") > ' this finds the correct text. > > ' where I want this to be displayed > txtboxname = ("Line0" & CStr(ctr)) ' dim'd as object gives error 91 > ' this holds the correct form textbox names > ' Me.Controls("txtboxname").Text > ' txtboxname dim'd as string gave error 2465 Tab Tests -(Keep) can't > find > the field "txtboxname .. > > Set txtboxname = varResult > ' when dim'd as string gives error 424 - object required > ' when dim'd as object gives > ' when dim'd as variant gives run-time error 13 type mismatch > Next ctr > End Sub > ... > I would sure like your help to make this work. > > Thanks, -- Fred >
From: Douglas J. Steele on 16 Jan 2010 15:52 Oops: Hit Enter too soon! I'm not really sure what you're trying to do. To refer to a control via a variable, you'd use Dim txtboxnamd As String txtboxname = "Line0" & CStr(ctr) and then use Me.Controls(txtboxname) You cannot refer to the Text property of a text box unless the text box has focus. Instead, refer to its Value property. The following code will work, but would put the same value into all 9 textboxes: Private Sub Form_Open(Cancel As Integer) Dim linecount As Integer ' Line conter (set to 9 for this test) Dim ctr As Integer ' Counter to be incremented Dim varResult As Variant ' will hold the answer Dlookup provides Dim txtboxname As String ' the name of form's textbox to be populated Dim selct As String ' A group indicator will come from a table selct = "W" ' W indicates Welcome linecount = 9 ' maximum number of lines to display For ctr = 1 To linecount ' the answer the text the table tbl field match value varResult = DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") txtboxname = "Line0" & CStr(ctr) Me.Controls(txtboxname).Value = varResult Next ctr End Sub or, more simply Private Sub Form_Open(Cancel As Integer) Dim linecount As Integer ' Line conter (set to 9 for this test) Dim ctr As Integer ' Counter to be incremented Dim selct As String ' A group indicator will come from a table selct = "W" ' W indicates Welcome linecount = 9 ' maximum number of lines to display For ctr = 1 To linecount Me.Controls("Line0" & CStr(ctr)) = _ DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") Next ctr End Sub -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "FKlusmann" <u57520(a)uwe> wrote in message news:a22d595a6f2f6(a)uwe... > Hello and thanks again. > I'd like to get several lines of text from a table and display them in > forms > textboxes. > > My table is TextTest01 with 3 fields (no PK, no index): > sel is text field size: 2 > lineNo is number long integer > line is text field size 80 > My unbound form fTestText01 has 10 textboxes named Line01, Line02 .. To > Line10. > > My code efforts are: > Private Sub Form_Open(Cancel As Integer) > Dim linecount As Integer ' Line conter (set to 9 for this test) > Dim ctr As Integer ' Counter to be incremented > Dim varResult As Variant ' will hold the answer Dlookup provides > Dim txtboxname As Variant ' the name of form's textbox to be populated > Dim selct As String ' A group indicator will come from a table > selct = "W" ' W indicates Welcome > linecount = 9 ' maximum number of lines to display > For ctr = 1 To linecount > ' the answer the text the table tbl field match value > varResult = DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") > ' this finds the correct text. > > ' where I want this to be displayed > txtboxname = ("Line0" & CStr(ctr)) ' dim'd as object gives error 91 > ' this holds the correct form textbox names > ' Me.Controls("txtboxname").Text > ' txtboxname dim'd as string gave error 2465 Tab Tests -(Keep) can't > find > the field "txtboxname .. > > Set txtboxname = varResult > ' when dim'd as string gives error 424 - object required > ' when dim'd as object gives > ' when dim'd as variant gives run-time error 13 type mismatch > Next ctr > End Sub > ... > I would sure like your help to make this work. > > Thanks, -- Fred >
From: FKlusmann via AccessMonster.com on 16 Jan 2010 17:03 Hi and thanks: You state: “I'm not really sure what you're trying to do.” I hope to give information in the (unbound) form of text lines from a table when some conditions are met. For a lack of any better idea I will unhide some textboxes (named Line01, Line02,…Line0n) and display them on the form. In this basic example, when 'Welcome' is selected, I would display the text in each table row field (named line) from the table (TextTest01) rows with selection (Field named sel matching “W”) and (Field named lineNo being numbers from 1 to n) . If I get this to work there will one place to change / add / correct text (and langueage) for the several forms in this project. I tried your suggested: [Quote] Private Sub Form_Open(Cancel As Integer) Dim linecount As Integer ' Line conter (set to 9 for this test) Dim ctr As Integer ' Counter to be incremented Dim varResult As Variant ' will hold the answer Dlookup provides Dim txtboxname As String ' the name of form's textbox to be populated Dim selct As String ' A group indicator will come from a table selct = "W" ' W indicates Welcome linecount = 9 ' maximum number of lines to display For ctr = 1 To linecount ' the answer the text the table tbl field match value varResult = DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") txtboxname = "Line0" & CStr(ctr) Me.Controls(txtboxname).Value = varResult Next ctr End Sub [End Quote] But get “Run-time error '2448': You can't assign a value to this object” at the line Me.Controls(txtboxname).Value = varResult I also tired: [Quote] Private Sub Form_Open(Cancel As Integer) Dim linecount As Integer ' Line conter (set to 9 for this test) Dim ctr As Integer ' Counter to be incremented Dim selct As String ' A group indicator will come from a table selct = "W" ' W indicates Welcome linecount = 9 ' maximum number of lines to display For ctr = 1 To linecount Me.Controls("Line0" & CStr(ctr)) = _ DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") Next ctr End Sub [End Quote] and also get: But get “Run-time error '2448': You can't assign a value to this object” at the line Me.Controls(txtboxname).Value = varResult I am open to any ideas and suggestions. Again, Thank you. -- Fred -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201001/1
From: Douglas J. Steele on 16 Jan 2010 20:15 You sure Line01, Line02 etc are text boxes and not some other type of control and that they're unbound? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "FKlusmann via AccessMonster.com" <u57520(a)uwe> wrote in message news:a2371f5abb9c1(a)uwe... > Hi and thanks: > You state: > “I'm not really sure what you're trying to do.” > I hope to give information in the (unbound) form of text lines from a > table > when some conditions are met. > > For a lack of any better idea I will unhide some textboxes (named Line01, > Line02,…Line0n) and display them on the form. In this basic example, when > 'Welcome' is selected, I would display the text in each table row field > (named line) from the table (TextTest01) rows with selection (Field named > sel > matching “W”) and (Field named lineNo being numbers from 1 to n) . > > If I get this to work there will one place to change / add / correct text > (and langueage) for the several forms in this project. > > I tried your suggested: > [Quote] > Private Sub Form_Open(Cancel As Integer) > Dim linecount As Integer ' Line conter (set to 9 for this test) > Dim ctr As Integer ' Counter to be incremented > Dim varResult As Variant ' will hold the answer Dlookup provides > Dim txtboxname As String ' the name of form's textbox to be populated > Dim selct As String ' A group indicator will come from a table > selct = "W" ' W indicates Welcome > linecount = 9 ' maximum number of lines to display > For ctr = 1 To linecount > ' the answer the text the table tbl field match value > varResult = DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") > txtboxname = "Line0" & CStr(ctr) > Me.Controls(txtboxname).Value = varResult > Next ctr > End Sub > [End Quote] > > But get “Run-time error '2448': You can't assign a value to this object” > at > the line > Me.Controls(txtboxname).Value = varResult > > I also tired: > [Quote] > Private Sub Form_Open(Cancel As Integer) > Dim linecount As Integer ' Line conter (set to 9 for this test) > Dim ctr As Integer ' Counter to be incremented > Dim selct As String ' A group indicator will come from a table > selct = "W" ' W indicates Welcome > linecount = 9 ' maximum number of lines to display > For ctr = 1 To linecount > Me.Controls("Line0" & CStr(ctr)) = _ > DLookup("[line]", "TextTest01", "[sel] = '" & [selct] & "'") > Next ctr > End Sub > [End Quote] > > and also get: > But get “Run-time error '2448': You can't assign a value to this object” > at > the line > Me.Controls(txtboxname).Value = varResult > > I am open to any ideas and suggestions. > > Again, Thank you. > > -- Fred > > -- > Message posted via AccessMonster.com > http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201001/1 >
|
Next
|
Last
Pages: 1 2 3 4 Prev: Curious Reaction to subform SQL statement Next: IF in a forms ON Load event... |