Update right field based on number passed

D

DDBeards

I have a master form with seven fields named tFeedBack1,
tFeedBack2...tFeedBack7. Each of these fields are found on seperate tabs
within the form. Each of these fields has a button I use to launch a new
Feedback form that has one field tFBNew. (same form will be used for all) I
need to do two functions, first check to see if the field on the master form
being updated is null or 0 length and second update the field on the master
form when the person is done entering the data. I have the code that works
great but I have to recreate it seven times based on which one of the seven
tFeedBack# fields are being updated. I would just like to pass it a value
like 1 through 7 and have the right field updated. Something like:

Forms!Master!tFeedback & passed value = tFBNew

However I do not not how to combine a varible with string to be used as a
field name on a form? Can someone please help. I will need this concatenated
field name used both in a isnull() and = line of code.

Thanks
 
V

Vincent Verheul

The master fields are probably stored in a table. The master form will be
linked to that table. In that case you can update the seven master fields
through the Form's RecordSet that is associated to the table.

In the Master Form use code like this:

Public Sub UpdateMasterField(FldName as String, FldValue as String)
Dim rs as DAO.RecordSet
set rs = Me.RecordSet
rs.Edit
rs.Fields(FldName).Value = FldValue
rs.Update
set rs = Nothing
End Sub

The master fields are assumed to be of the type String
The correct field is found through its name in the RecordSet "Fields"
collection.

You can call this function from another form using the Syntax Call
[Form_Master Form].UpdateMasterField("tFeedBack1", tFBNew) Assuming the
name of the master form is "Master Form".
 
R

rquintal

I have a master form with seven fields named tFeedBack1,
tFeedBack2...tFeedBack7. Each of these fields are found on seperate tabs
within the form.  Each of these fields has a button I use to launch a new
Feedback form that has one field tFBNew. (same form will be used for all) I
need to do two functions, first check to see if the field on the master form
being updated is null or 0 length and second update the field on the master
form when the person is done entering the data.  I have the code that works
great but I have to recreate it seven times based on which one of the seven
tFeedBack# fields are being updated.  I would just like to pass it a value
like 1 through 7 and have the right field updated.  Something like:

Forms!Master!tFeedback & passed value = tFBNew

However I do not not how to combine a varible with string to be used as a
field name on a form?  Can someone please help. I will need this concatenated
field name used both in a isnull() and = line of code.

Thanks

You are struggling with this because the table design is wrong.

The recurring fields tFeedback (1 to 7) shoukld be zero to seven rows
in a sub table, with three fields,
1) the reference to the main table, 2) the sequence number 1 to seven
and 3) the FeedBack field.

You would show these records using a subform on the master form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top