By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,483 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,483 IT Pros & Developers. It's quick & easy.

How to insert values into a textbox in MS Access 2007

P: 6
I have a problem while inserting values into textboxes. The textboxes are created dynamically. Now i would like to insert data into these textboxes and display in the form.

In the code txtday& i & k is the dynamically created textbox. I am able to create textbox. But not able to insert data into it. The above statement is working fine.
Expand|Select|Wrap|Line Numbers
  1. Forms!result!txtday.Value = days
  2.  


But i am getting error when &i & k are inserted to code. message says
" Compile error:
Expected: = "


I would like to know the syntax for inserting data.

Thanks

Expand|Select|Wrap|Line Numbers
  1. Public gv_wcnum As String
  2. Public Function get_schedule()
  3.  
  4. Dim days, shifts, total As Integer
  5. Dim i,k as Integer
  6. For i = 1 to 20
  7.   For k = 1 to 8
  8.  
  9. days = 30/3
  10. Forms!result!txtday"& i & k".value = days
  11. next k
  12. next i
  13. End Function 
  14.  
Nov 2 '11 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,709
FNemo:
The textboxes are created dynamically.
Where? How? Please show us your code for this.

The code you have shown us is meaningless as it doesn't even compile (See When Posting (VBA or SQL) Code). Maybe it might make some sense if you posted the code that creates the TextBoxes, but alone it's without any value whatsoever (It's a bit like saying my code asdfghjk doesn't work. Well, of course it doesn't. The compiler tells you that). Without the other code it needs a properly presented question to explain what you want. This is a good attempt, but not a proper question as it stands (Frankly a good attempt is better than most so I'm happy, but a full question is required still). I can't suggest a solution to you as I don't have your question.
Nov 2 '11 #2

P: 6
The below program is my code. i have indicated where problem is arising.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_ok_Click()
  2.  
  3. Dim intNumOfRecords As Integer
  4.     Dim i As Integer
  5.     Dim x As String
  6.  
  7.     Dim ctltext As Control
  8.     Dim intDataX As Integer
  9.     Dim intDataY As Integer
  10.  
  11.     Dim intDataHeight As Integer
  12.     Dim intDataWidth As Integer
  13.     Dim intDataTop As Integer
  14.     Dim intDataLefy As Integer
  15.  
  16.     Dim x As Integer
  17.     Dim y As Integer
  18.  
  19.     intDataWidth = 2000
  20.     intDataHeight = 250
  21.     intDataTop = 100
  22.     intDataLeft = 100
  23.  
  24.     intNumOfRecords = 8
  25.     Data = 6
  26.  
  27.     For i = 1 To intNumOfRecords
  28.  
  29.     DoCmd.OpenForm "Search_bookid", acDesign
  30.     Set ctltext = CreateControl("Search_bookid", acTextBox, acDetail)
  31.  
  32.     With ctltext
  33.         .Name = "txtwc" & i
  34.         .Left = intDataLeft
  35.         .Top = intDataTop
  36.         .Width = intDataWidth
  37.         .Height = intDataHeight
  38.         .Visible = True
  39.  
  40.     End With
  41.     intDataTop = intDataTop + 400
  42.  
  43.     DoCmd.Restore
  44.     DoCmd.Close acForm, "Search_bookid", acSaveYes
  45.     DoCmd.OpenForm "Search_bookid", acNormal
  46.     Forms!Search_bookid!txtwc"& i".value = 8   
  47. 'this is where syntax error is coming. This is where i am inserting data into textbox
  48.     DoCmd.Close acForm, "Search_bookid", acSaveYes
  49.    Next i
  50.  
  51.    End Sub
  52.  
Nov 3 '11 #3

NeoPa
Expert Mod 15k+
P: 31,709
I see. Sorry for the delay BTW.

Your code :
Expand|Select|Wrap|Line Numbers
  1. Forms!Search_bookid!txtwc"& i".value = 8
should be written as :
Expand|Select|Wrap|Line Numbers
  1. Forms!Search_bookid.Controls("txtwc" & i) = 8
PS. You can set the value in the design part of the code (Lines #33 to #39) too, as an alternative, if you wanted to.
Nov 11 '11 #4

P: 6
Thanks for the reply.
Nov 12 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.