How to insert values into a textbox in MS Access 2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fnemo
    New Member
    • Oct 2011
    • 6

    How to insert values into a textbox in MS Access 2007

    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.
    Code:
    Forms!result!txtday.Value = days


    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

    Code:
    Public gv_wcnum As String
    Public Function get_schedule()
    
    Dim days, shifts, total As Integer
    Dim i,k as Integer
    For i = 1 to 20
      For k = 1 to 8
    
    days = 30/3
    Forms!result!txtday"& i & k".value = days
    next k
    next i
    End Function
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    Originally posted by FNemo
    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.

    Comment

    • fnemo
      New Member
      • Oct 2011
      • 6

      #3
      The below program is my code. i have indicated where problem is arising.
      Code:
      Private Sub cmd_ok_Click()
      
      Dim intNumOfRecords As Integer
          Dim i As Integer
          Dim x As String
          
          Dim ctltext As Control
          Dim intDataX As Integer
          Dim intDataY As Integer
          
          Dim intDataHeight As Integer
          Dim intDataWidth As Integer
          Dim intDataTop As Integer
          Dim intDataLefy As Integer
          
          Dim x As Integer
          Dim y As Integer
          
          intDataWidth = 2000
          intDataHeight = 250
          intDataTop = 100
          intDataLeft = 100
          
          intNumOfRecords = 8
          Data = 6
          
          For i = 1 To intNumOfRecords
      
          DoCmd.OpenForm "Search_bookid", acDesign
          Set ctltext = CreateControl("Search_bookid", acTextBox, acDetail)
           
          With ctltext
              .Name = "txtwc" & i
              .Left = intDataLeft
              .Top = intDataTop
              .Width = intDataWidth
              .Height = intDataHeight
              .Visible = True
              
          End With
          intDataTop = intDataTop + 400
         
          DoCmd.Restore
          DoCmd.Close acForm, "Search_bookid", acSaveYes
          DoCmd.OpenForm "Search_bookid", acNormal
          Forms!Search_bookid!txtwc"& i".value = 8   
      'this is where syntax error is coming. This is where i am inserting data into textbox
          DoCmd.Close acForm, "Search_bookid", acSaveYes
         Next i
          
         End Sub

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32662

        #4
        I see. Sorry for the delay BTW.

        Your code :
        Code:
        Forms!Search_bookid!txtwc"& i".value = 8
        should be written as :
        Code:
        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.
        Last edited by NeoPa; Nov 11 '11, 05:32 PM.

        Comment

        • fnemo
          New Member
          • Oct 2011
          • 6

          #5
          Thanks for the reply.

          Comment

          Working...