Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am a bit of a beginner with access but am picking it up pretty quickly. I need to get my form to lookup a structure name and return it to a text box by typing in the corresponding structure no. I have all the details in a query but not sure what to do next.
Thanks

Anthony, does this help you in some way by chance? Dim db As DAO.Database Dim rs As DAO.Recordset Dim strSQL As String Dim strList As String Set db = CurrentDb strSQL = "SELECT Products.ProductName " & _ "FROM Products " & _ "INNER JOIN Categories " & _ "ON Products.CategoryID = Categories.CategoryID " & _ "WHERE Categories.CategoryName='Beverages'; " Set rs = db.OpenRecordset(strSQL, dbOpenDynaset) With rs Do While Not .EOF strList = strList & rs!ProductName & ", " .MoveNext Loop End With 'Trim last comma If Right(strList, 2) = ", " Then strList = Left(strList, Len(strList) - 2) End If Me.Text0 = strList Set rs = Nothing Set db = NothingIn the VBA code, you can basically run your query and put the result(s) of the query into a record set. Then you can do whatever with the record set.
Me.txtBoxName.Text = rs!NameOfFieldFromQueryResultI do not know though if I understand your situation correctly.

Dim dbs As Database, qdf As QueryDef, strSQL As String
Set dbs = CurrentDbstrSQL = "SELECT * FROM All_record_New WHERE (((All_record_New.[Physical Zip - US Only])=[Forms]![All_record1]![ZIP]) AND ((All_record_New.[Est Tot Wireline Communications Bill - Most Likely]) >= [Forms]![All_record1]![Est1] AND (All_record_New.[Est Tot Wireline Communications Bill - Most Likely])<= [Forms]![All_record1]![EST2]) AND ((All_record_New.[Emp Here]) >= [Forms]![All_record1]![EMP1] AND (All_record_New.[Emp Here]) <= [Forms]![All_record1]![EMP2]) AND And ((All_record_New.[Physical Street Address Line 1]) LIKE ('*'+[Forms]![All_record1]![FPA]+'*')));"
Set qdf = dbs.CreateQueryDef("qry" + Forms!All_record1!ZIP, strSQL)
DoCmd.OpenQuery ("qry" + [Forms]![All_record1]![ZIP])

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |