populate a combo box control on form 2 depending on which form (form 1) opened it.

SteveJtoo

Registered User.
Local time
Today, 14:22
Joined
Sep 26, 2012
Messages
50
I have a database of books. I have a combobox listing 3 different status W M R.
W is for Whats next to read, M is for more books too read and R for books read or reading now. I can enter a new book by calling up the add a book form from any of those 3 forms. If I forget to enter a letter in the combo box then the book is lost to those 3 forms as what they see depends on that status letter and I have to go to the table and enter a letter from there. I want to know if I can auto populate the field (W M R) depending on which form opened the add a book form. I hope this is understandable! Thanks for any help or suggestions.
 
Use the Docmd.OpenForm OpenArgs property.
Code:
DoCmd.OpenForm "frmAddBook", acNormal, , , , , "W"
The OpenArgs is the last variable in the command and here is where you can put W, M or R. Then, in the forms On_Open event do something like:
Code:
If Not IsNull(Me.OpenArgs) Then
Me.ComboBox1.DefaultValue = """" & Me.OpenArgs & """"
End If
This will then set the default value of your combobox so you don't need to manually set the value when you enter a new record.
 
Thanks for your help. My final solution is to do it all on the first form. You gave me the idea and this way seems to work.
Code:
DoCmd.OpenForm "Books Detail", acNormal, , , acFormAdd, , "W"
 

Users who are viewing this thread

Back
Top Bottom