mc access forms and getting data from a recordset into a form

  • Thread starter Thread starter Scott Trowbridge
  • Start date Start date
S

Scott Trowbridge

Hello,

I've got a module that has a function that I'm reading data from into a
recordset; which works very nicely. Now I'm tring to read information from
'dealer_rst' structure and fill in fields on a form (ie. me.dealer_name =
daler_rst!dealer_name). But as you can guess it doesn't work. Someone
recommended using:

grid.datasource.recordset.fields("nameofa field")

but... there is very little out on the internet on this function that I can
understand.


Can anyone point me in the right direction?


Scott

***********************************************************



Public dealer_rst As DAO.Recordset

-----------------------------------------------

Function check_dealer(needed_dealer As String)

On Error GoTo Err_on_check_dealer

Set dealer_rst = CurrentDb.OpenRecordset("SELECT dealer.* " & _
" FROM dealer WHERE ((DEALER)= '" & needed_dealer &
"')")

check_dealer = dealer_rst.recordcount

Exit Function

Err_on_check_dealer:

check_dealer = -1

system_log_file ("Error ->ERR #: " & Err.Number & _
" DESC: " & Err.Description & _
" FUNCT: check_dealer() No variable.")

End Function
Function check_ALL_dealer()

On Error GoTo Err_on_check_ALL_dealer

Set dealer_rst = CurrentDb.OpenRecordset("SELECT dealer.* FROM dealer")


check_ALL_dealer = dealer_rst.recordcount

Exit Function

Err_on_check_ALL_dealer:

check_ALL_dealer = -1

system_log_file ("Error ->ERR #: " & Err.Number & _
" DESC: " & Err.Description & _
" FUNCT: check_ALL_dealer() No variable.")

End Function
 
Why not just open the form and use the where clause like:

dim strWhere as string

stWhere = "Dealer = '" & needed_dealer & "'"

docmd.OpenForm "youForm",,,strWhere

The above is all you need.

If, for some strange reason, you need to set the forms reocrdset, then just
go:

dim strSql as string

strSql = "SELECT * FROM dealer " & _
"WHERE DEALER = '" & needed_dealer & "'"

Me.RecordSouce = strSql

So, if as you show you have the conditions, then use the first example with
the "where" clause, and if you "must" produce the sql, then simply stuff
that sql into the forms reocrdset.....no need to try and create the
reocrdset first....is there??
 
This form has a header area, where one set of data will be displayed, and
the detail lines. I plan on setting the recordset for the
form to bring up all the detail lines, but wanted to fill-in the fields
using pieces of data that have already been lookup prior to moving
to this screen from a variety of recordsets.

Scott
 
That is fair answer. You can in fact assign a recordset to a form..but it
usually is NOT updateable.

So, I would simply save your sql you used to generate the reocrdset and as I
showed...just stuff in the sql to the forms reocrdsouce.

If possible, you could also just stuff the sql into the forms reocrdsouce,
and then reference/use the record set it creates for you.


me.ReocrdSetClone.ReocrdCount
me.ReocrdSetClone.FindFirst

etc.
 
Back
Top