Populate text box

  • Thread starter Thread starter Wayne Livingstone
  • Start date Start date
W

Wayne Livingstone

Hi...

I've gotten this far with my code:

'Start
Dim strSqlSelect4 As String
Dim strSqlOrder4 As String
Dim strSqlWhere4 As String

'Create SQL Query
strSqlSelect4 = "SELECT PrintFeeID " & _
"FROM [PrintingFees] "

'Where
strSqlWhere4 = " WHERE [PrintingFees].Plotter =" _
& Chr$(34) & [Forms]![PlotSelect]![Plotter] & Chr$(34) _
& " AND [PrintingFees].Paper =" _
& Chr$(34) & [Forms]![PlotSelect]![Paper] & Chr$(34) _
& " AND [PrintingFees].Colour =" _
& Chr$(34) & [Forms]![PlotSelect]![Colour] & Chr$(34)


This code will produce a unique PrintFeeID. I need to put
this PrintFeeID into a text field on my form or possibly
directly into the table.

I would also like to make an expression of the values from
Plotter, Paper and Colour in the form of "Plotter : Paper :
Colour" and place this into a text field or directly into
the table.

I hope someone can show me how this can be done.

Thanks
 
I'm assuming that the textbox is bound to a field so that its Control Source
needs to be the name of that field. And that this is why you're using code
to get the value.

All you need to do is to open a recordset based on your query, and then
write it to the textbox. Something like this:



'Start
Dim strSqlSelect4 As String
Dim strSqlOrder4 As String
Dim strSqlWhere4 As String

Diim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb()

'Create SQL Query
strSqlSelect4 = "SELECT PrintFeeID " & _
"FROM [PrintingFees] "

'Where
strSqlWhere4 = " WHERE [PrintingFees].Plotter =" _
& Chr$(34) & [Forms]![PlotSelect]![Plotter] & Chr$(34) _
& " AND [PrintingFees].Paper =" _
& Chr$(34) & [Forms]![PlotSelect]![Paper] & Chr$(34) _
& " AND [PrintingFees].Colour =" _
& Chr$(34) & [Forms]![PlotSelect]![Colour] & Chr$(34)

strSQL = strSqlSelect4 & srSqlWhere4 & strSqlOrder4 & ";"

Set rst = dbs.OpenRecordset(strSQL)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
Me.TextboxName.Value = rst.Fields(0).Value
Else
MsgBox "No PrintFee found."
Me.TextboxName.Value = Null
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
 
Wayne said:
I've gotten this far with my code:

'Start
Dim strSqlSelect4 As String
Dim strSqlOrder4 As String
Dim strSqlWhere4 As String

'Create SQL Query
strSqlSelect4 = "SELECT PrintFeeID " & _
"FROM [PrintingFees] "

'Where
strSqlWhere4 = " WHERE [PrintingFees].Plotter =" _
& Chr$(34) & [Forms]![PlotSelect]![Plotter] & Chr$(34) _
& " AND [PrintingFees].Paper =" _
& Chr$(34) & [Forms]![PlotSelect]![Paper] & Chr$(34) _
& " AND [PrintingFees].Colour =" _
& Chr$(34) & [Forms]![PlotSelect]![Colour] & Chr$(34)


This code will produce a unique PrintFeeID. I need to put
this PrintFeeID into a text field on my form or possibly
directly into the table.

I would also like to make an expression of the values from
Plotter, Paper and Colour in the form of "Plotter : Paper :
Colour" and place this into a text field or directly into
the table.


It would be easier to use a DLookup to get the PrintFeeID
from the table:

txtPrintFeeID=DLookup("PrintFeeID","PrintingFees",strSqlWhere4)

To display the combined values in another text box, just use
an expression in the text box:

=Plotter & " : " & Paper & " : " & Colour
 
Back
Top