Rufus
Rufus

Reputation: 37

Populating a form from a table

I'm not sure if I used the right title for this question but I'll try to ask it. Be patient with me I'm new to Microsoft Access.

I'm making an MS-Access database for employee reviews at my company and I made the form and all of the data from the form is going to two seperate table. The tables are linked through the same rating ID for each time the form is filled.

I have a seperate form that when you select the name of the stakeholder reviewed it fills a listbox with the name of the leader who reviewed them, the date, and the rating ID. I used VB to make it to where if you select the rating ID then it will open the form in which the data was put into using DoCmd.OpenForm "FRM".

Now for the question I hope that was all understandable. I would like for the form that is brought up from selecting the rating ID to be repopulated with all of the information that was entered into the table for that specific ID. What do I need to do to do this?

Upvotes: 0

Views: 264

Answers (2)

Andy G
Andy G

Reputation: 19367

Another option is to base the form on a table or query (its RecordSource) and use the Where clause argument when opening the form:

DoCmd.OpenForm "frmName", acNormal, , "[SomeID]=" & frmYours!ctlControlName

This has the advantage that the form can be opened separately, as it will just show all the data from its RecordSource, not producing an unwanted parameter request.

If SomeID is text then its value needs to be quoted with apostrophes:

DoCmd.OpenForm "frmName", acNormal, , "[SomeID]='" & frmYours!ctlControlName & "'"

Upvotes: 2

Barranka
Barranka

Reputation: 21057

There are various possible solutions to this.

The first one (and simplest) is to write a query in the RowSource property of your form with the appropriate data source, and include a filter field in that query that corresponds to the Id you are filtering:

select a.*
from [your table] as a
where a.[id] = forms!frmYourForm![theControlName]

That way, every time you open the form, it will show the appropriate data.

The second solution (a little more sophisticated) is to edit the RowSource property on run-time. In the code that opens the form, you can do something like this:

strSQL = "select a.* from [your table] as a where a.Id = " & theControlName.Value
DoCmd.OpenForm "theDetailedForm"
form_theDetailedForm.RowSource = strSQL
form_theDetailedForm.Requery

Hope this helps you

Upvotes: 0

Related Questions