Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fill text boxes with table data 1

Status
Not open for further replies.

nikademous

Technical User
Sep 9, 2018
41
US
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..
 
I wanted all lengths visable at one time like a picker
 
Is there a reason you don't use a simple list box to select the length? :)


---- Andy

There is a great need for a sarcasm font.
 
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:
Private Sub Form_Open(Cancel As Integer)
[COLOR=#4E9A06]    ' 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[/color]
    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
 
How are ya nikademous,

Consider a [blue]popup form[/blue] linked to the table or with a [blue]Listbox[/blue] linked to the table ...

Your Thoughts? ...

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
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?
 
Code:
[blue]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")
       [b] Me.Controls("txt" & i).Width = Me.Controls("txt" & i).Width - 15
        Me.Controls("txt" & i).Height = Me.Controls("txt" & i).Height - 15[/b]
        rs.MoveNext
    Next
    rs.Close
    Set rs = Nothing
End Sub

Public Function getValue(p As Integer) As String
    [b]Static lastp As Long[/b]

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

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

End Function

Public Function putValue(p As Integer) As String
    [b]Static lastp As Long[/b]
    
    Me.txtSelected = DLookup("inValue", "tbl_Inches", "pos=" & p)
    Me.cmdEnterClose.Caption = "Insert Selected"
    Me.txtDummy.SetFocus
    
    [b]If lastp <> 0 Then Me.Controls("txt" & lastp).BorderWidth = 1
    Me.Controls("txt" & p).BorderWidth = 2
    lastp = p[/b]
    
End Function[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top