Make varying fields appear on form (depending on the value in fiel

G

Guest

I want to have fields A, B, C and D show up on a form if the value in a
certain field X is "1", and fields A, B, E and F show up if the value in
field X is "2".

In other words, as I move through the various records on the form, some
would show fields A, B, C and D and others would show fields A, B, E and F.

I can't figure out how to make this happen... Is there anybody who has a
suggestion? (Thanks for any replies).
 
B

Brendan Reynolds

In the Form_Current event procedure ...

If X = "1" Then
txtCorE.ControlSource = "C"
txtDorF.ControlSource = "D"
Else
txtCorF.ControlSource = "E"
txtDorF.ControlSource = "F"
End If
 
G

Guest

Brendan,

I tried this code and was unable to make it work. I get an error on the
following line: txtCorF.ControlSource = "E"

Thanks for any help you can provide in this regard.

Derek (Slappy)
 
G

Guest

Yes...you can probably tell that I am not a programmer...I think I've worked
out that problem...but what I REALLY want to be able to do is call up a
unique form based on the value in a field...If you could take a look at what
I've written below and comment on it, I would be extremely grateful.

My practise database is called "Beatles". It is based on one table named
"Hardware Preferences". The fields in the table are:

1. name
2. instrument
3. type_of_guitar_strings_used
4. type_of_bass_strings_used
5. type_of_drumsticks_used

On my form, if the record for "John" is selected, I want the form to show
only the following fields: 1. name 2. instrument 3.
type_of_guitar_strings_used.

If the record for "Paul" comes up, I want the form to show only the
following fields: 1. name 2. instrument 3. type_of_bass_strings_used.

Ringo's record would show type_of_drumsticks_used and George's would be like
John's.

Given the complication of the actual database that this plan is based on, I
don't think it is feasible to have the appropriate fields simply hidden until
they are needed. I actually need one of seven different forms to come up for
each record based on the value in one particular field in the record.

Thanks for taking the time to read this!
 
B

Brendan Reynolds

Use code similar to that I posted earlier to determine which member of the
Beatles (or whatever the real condition is) the current record represents.
Use the DoCmd.OpenForm method to open the appropriate form. Use the
WhereCondition argument of the DoCmd.OpenForm method to filter that form to
display the appropriate record or records. Here's an example that uses
tables from Microsoft's 'Northwind' sample database ...

Private Sub cmdTest_Click()

If Me.CustomerID = "ALFKI" Then
DoCmd.OpenForm "Customers1", , , "CustomerID = 'ALFKI'"
Else
DoCmd.OpenForm "Customers2", , , "CustomerID = '" & Me.CustomerID &
"'"
End If

End Sub

Here's a link to the on-line help topic on the OpenForm method ...

http://msdn.microsoft.com/library/d.../vbaac11/html/acmthactOpenForm_HV05186497.asp
 
G

Guest

Thank you very much for the help. I'll study this and read the article.

Derek (Slappy)
 

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