×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Fill text boxes with table data

Fill text boxes with table data

Fill text boxes with table data

(OP)
Hello, I have a table tbl_Sizes and it's field (lengths) has all measurements up to 2"inches. I need to create a picked for those lengths. I wanted to create let's say 40 text boxes named (txt1, txt2) and when the for opens it populates each text box with the data from the table and when clicked on it moves the length to my form.

Any example VB would be appreciated! Thanks..

RE: Fill text boxes with table data

Is there a reason you don't use a simple combo box to select the length?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Fill text boxes with table data

(OP)
I wanted all lengths visable at one time like a picker

RE: Fill text boxes with table data

Is there a reason you don't use a simple list box to select the length? smile


---- Andy

There is a great need for a sarcasm font.

RE: Fill text boxes with table data

Ok, let's use toggle buttons since they are more appropriate than text boxes. I created a form with an option group and 13 toggle buttons.

CODE --> vba

Private Sub Form_Open(Cancel As Integer)
    ' create a option group frame and add toggle buttons
    ' name the toggle buttons tog1, tog2, tog3,...
    ' as a toggle button is selected, the option group value will be the appropriate lengths value
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    Dim intN As Integer
    Set db = CurrentDb
    strSQL = "SELECT Lengths FROM tbl_Sizes"
    Set rs = db.OpenRecordset(strSQL)
    rs.MoveFirst
    For intN = 1 To 13   'you number could be higher
        Me("tog" & intN).Caption = rs.Fields("lengths")
        Me("tog" & intN).OptionValue = rs.Fields("lengths")
        rs.MoveNext
    Next
    rs.Close
    Set rs = Nothing
    Set db = Nothing
End Sub 

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Fill text boxes with table data

This may be fine of you know how many controls you need, which you do.
But, if you want to create controls 'on-the-fly' (dynamically), in the code, see this post: How to create controls at run time Access VB?


---- Andy

There is a great need for a sarcasm font.

RE: Fill text boxes with table data

(OP)
Ok I been messing with using text boxes to fill the length and im using a mouse over to display length. Next I want to highlight the moused over control, how can I do that?

RE: Fill text boxes with table data

CODE

Private Sub Form_Open(Cancel As Integer)
    Dim strSQL As String
    Dim i As Integer
    Dim rs As DAO.Recordset

    strSQL = "SELECT inValue FROM tbl_Inches"

    'Debug.Print strSql
    Set rs = CurrentDb.OpenRecordset(strSQL)

    rs.MoveFirst
    For i = 1 To 64
        Me.Controls("txt" & i) = rs.Fields("inValue")
        Me.Controls("txt" & i).Width = Me.Controls("txt" & i).Width - 15
        Me.Controls("txt" & i).Height = Me.Controls("txt" & i).Height - 15
        rs.MoveNext
    Next
    rs.Close
    Set rs = Nothing
End Sub

Public Function getValue(p As Integer) As String
    Static lastp As Long

    Me.txtReading = DLookup("inValue", "tbl_Inches", "pos=" & p)

    If lastp <> 0 Then Me.Controls("txt" & lastp).BorderColor = vbBlack
    Me.Controls("txt" & p).BorderColor = vbRed
    lastp = p

End Function

Public Function putValue(p As Integer) As String
    Static lastp As Long
    
    Me.txtSelected = DLookup("inValue", "tbl_Inches", "pos=" & p)
    Me.cmdEnterClose.Caption = "Insert Selected"
    Me.txtDummy.SetFocus
    
    If lastp <> 0 Then Me.Controls("txt" & lastp).BorderWidth = 1
    Me.Controls("txt" & p).BorderWidth = 2
    lastp = p
    
End Function 

RE: Fill text boxes with table data

The final errors out since it can'f find the function on the mouse move event.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close