Data from table

S

Stephanie

I have a table with tons of data on it. In my form I have it set so I have a
combo box for the main item. When I click on it, I want all of the
correlating data in that file to show up in the appropriate fields in the
form. How do I do that?

I know I've done it before, I just don't remember how.

Thanks
 
K

Klatuu

I don't remember how you did it last time, either, but here is how it is done:

You use the After Update event of the combo box to make the selected record
the current record:

Private Sub cboTonsOData_AfterUpdate()

With Me.RecordsetClone
.FindFirst "[SomeKeyField] = " & Me.cboTonsOData
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End IF
End With
End Sub

In the example above, the assumption is SomeKeyField is numeric. If not,
use the appropriate delimiters:
Text:
.FindFirst "[SomeKeyField] = '" & Me.cboTonsOData & "'"
Date:
.FindFirst "[SomeKeyField] = #" & Me.cboTonsOData & "#"
 
S

Stephanie

Thanks, Dave. I'll give it a try.

--
Steph


Klatuu said:
I don't remember how you did it last time, either, but here is how it is done:

You use the After Update event of the combo box to make the selected record
the current record:

Private Sub cboTonsOData_AfterUpdate()

With Me.RecordsetClone
.FindFirst "[SomeKeyField] = " & Me.cboTonsOData
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End IF
End With
End Sub

In the example above, the assumption is SomeKeyField is numeric. If not,
use the appropriate delimiters:
Text:
.FindFirst "[SomeKeyField] = '" & Me.cboTonsOData & "'"
Date:
.FindFirst "[SomeKeyField] = #" & Me.cboTonsOData & "#"

--
Dave Hargis, Microsoft Access MVP


Stephanie said:
I have a table with tons of data on it. In my form I have it set so I have a
combo box for the main item. When I click on it, I want all of the
correlating data in that file to show up in the appropriate fields in the
form. How do I do that?

I know I've done it before, I just don't remember how.

Thanks
 
S

Stephanie

Okay. Think I wasn't clear.

Have a table called FDA that contains tons of data.
Have table called Log
Have table called Daily totals
Have a query called Foods_qry

The source for the form is the query. The source for the field called Food
is the table FDA. This is what I did based on what you said...

With Me.RecordsetClone
.FindFirst "[Calories] = " & Me.Food
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If

I get an error: Run Time Error '3077' Syntax error (comma) in expression.
It points to .FindFirst "[Calories] = " & Me.Food

Obviously I'm doing something wrong...
Help please.
 
Top