display query data on a form

N

Nick T

Hi,
Can i display query data onto a form (in text boxes) using some code behind
a command button?
I currently have the following code, which displays one of my queries
records (the first record of potentially several) however i want my form to
display all records in my query where the 'sequenceNo' appears:

Private Sub ShowDetail_Click()
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("BatchIngredientDetail", dbOpenDynaset)
With rst
.FindFirst "[SequenceNo] = " & Me.Batch

Me.BatchNo = !SequenceNo
Me.RMCode = !RawMaterialCode
Me.RMDescription = !Description
Me.TargetWeight = ![Sum Of WeightStd]
Me.ActualWeight = ![Sum Of WeightActual]

.Close
End With
Set rst = Nothing

End Sub

I hope this makes sence, however basically, i want to display on my form all
of the query records where the 'SequenceNo' matches a 'Batch' number which i
type into a text box. (the above code is behind a cmd button, so all a user
has to do is input a batch number & click the cmd button)

Hope somone can help.

Many thanks
 
J

Jeff Boyce

Nick

If I'm reading it right, your code only finds the first one.

Have you looked into using a query instead to return the recordset?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
N

Nick T

Hi Jeff,
Yes, my code does currently only return the first one. How can i get it to
return all of the relevant records in my query??

There are various records in my query which have the same 'sequenceNo' & i
want all of them displayed on my form.

Thanks for the help - hope to hear back.



Jeff Boyce said:
Nick

If I'm reading it right, your code only finds the first one.

Have you looked into using a query instead to return the recordset?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Nick T said:
Hi,
Can i display query data onto a form (in text boxes) using some code
behind
a command button?
I currently have the following code, which displays one of my queries
records (the first record of potentially several) however i want my form
to
display all records in my query where the 'sequenceNo' appears:

Private Sub ShowDetail_Click()
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("BatchIngredientDetail",
dbOpenDynaset)
With rst
.FindFirst "[SequenceNo] = " & Me.Batch

Me.BatchNo = !SequenceNo
Me.RMCode = !RawMaterialCode
Me.RMDescription = !Description
Me.TargetWeight = ![Sum Of WeightStd]
Me.ActualWeight = ![Sum Of WeightActual]

.Close
End With
Set rst = Nothing

End Sub

I hope this makes sence, however basically, i want to display on my form
all
of the query records where the 'SequenceNo' matches a 'Batch' number which
i
type into a text box. (the above code is behind a cmd button, so all a
user
has to do is input a batch number & click the cmd button)

Hope somone can help.

Many thanks
 
J

Jeff Boyce

Nick

That FindFirst command does just that, only finds the first one.

Have you tried creating a query that returns the records you want to see?

Once you have that query working, where did you want to see/use those
records?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Nick T said:
Hi Jeff,
Yes, my code does currently only return the first one. How can i get it
to
return all of the relevant records in my query??

There are various records in my query which have the same 'sequenceNo' & i
want all of them displayed on my form.

Thanks for the help - hope to hear back.



Jeff Boyce said:
Nick

If I'm reading it right, your code only finds the first one.

Have you looked into using a query instead to return the recordset?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Nick T said:
Hi,
Can i display query data onto a form (in text boxes) using some code
behind
a command button?
I currently have the following code, which displays one of my queries
records (the first record of potentially several) however i want my
form
to
display all records in my query where the 'sequenceNo' appears:

Private Sub ShowDetail_Click()
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("BatchIngredientDetail",
dbOpenDynaset)
With rst
.FindFirst "[SequenceNo] = " & Me.Batch

Me.BatchNo = !SequenceNo
Me.RMCode = !RawMaterialCode
Me.RMDescription = !Description
Me.TargetWeight = ![Sum Of WeightStd]
Me.ActualWeight = ![Sum Of WeightActual]

.Close
End With
Set rst = Nothing

End Sub

I hope this makes sence, however basically, i want to display on my
form
all
of the query records where the 'SequenceNo' matches a 'Batch' number
which
i
type into a text box. (the above code is behind a cmd button, so all a
user
has to do is input a batch number & click the cmd button)

Hope somone can help.

Many thanks
 

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