0

I have a Main form in formview and a related subform in datasheet view asking results to the same query.

In the Main form i have a "free" textbox that is not linked to any query field. This textbox is an "input" value that i want to use for a module/function that will assign the txtbox.value to ALL the values under a query field. Example:

Main Form:

Private Sub Command1_Click()
Dim txtbox As String
Dim qryField as String
Dim FieldName as String
Dim subfrm as Object

txtbox = textbox.Value
FieldName = "Data"
qryField = Me.RecordSource & "." & FieldName
subfrm = subfrmOfMain

Call AssignValueToAllFieldValues (subfrm, txtbox, qryField)
End Sub

In the module/function:

Public Sub AssignValueToAllFieldValues (Byval subfrm as Object, Byval txtbox as String, Byval qryField as String)

For each qryField.value in subfrm.qryField
  "assign txtbox.value to qryField.value"
Next
End Sub

This doesn't work of course..

5
  • Update field in underlying table with an UPDATE action SQL. Commented Feb 6, 2020 at 21:43
  • can you tell me how please? Commented Feb 6, 2020 at 21:59
  • Code like CurrentDb.Execute "UPDATE tablename SET fieldname=" & Me.textboxname & "'". If field is number type remove apostrophe delimiters, if it is date/time type use # delimiter. Use a WHERE clause if need to restrict records. Commented Feb 6, 2020 at 23:26
  • Rats! Missing first apostrophe after = sign in my example. Commented Feb 6, 2020 at 23:34
  • I was trying with your solution many times till at i understood that i have to use delimiters even in the WHERE clause... Now all works well! Plz make your comments as a solution to my question so i can flag as a good solution! Commented Feb 8, 2020 at 15:49

1 Answer 1

1

Update field in underlying table with an UPDATE action SQL. Code like:

CurrentDb.Execute "UPDATE tablename SET fieldname='" & Me.textboxname & "'".

Remove apostrophe delimiters for number type field; for date/time type use # delimiter. Use a WHERE clause if need to restrict records. Apply delimiters as needed for parameters in WHERE clause as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.