Help with DAO. Recordset

  • Thread starter jayjay21us via AccessMonster.com
  • Start date
J

jayjay21us via AccessMonster.com

I'm very new to dealing with DAO Recordset... I"m trying the following to
populate a form with unbound text fields... I have 10 unbound text boxes.. D0
thru D9. I want the result of the recordset to populate the unbound text
boxes. But I don't know how to do so..I search and googled, but I'm confused.
.. So I got this to work to at least it tells me I'm going in the right
direction... Any help would be appreciated....


Option Compare Database
Sub DisplayWeekly()
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("SELECT DocketID, PLFirst, PLLast FROM
HearingSchedule", dbOpenDynaset)
Do While Not rs.EOF
Debug.Print rs![DOCKETID]; rs![PLFIRST]; rs![PLLAST]
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
End Sub

I did the Debug.Print to see if it was returning what I want.. and it is... I
just can't get update the script to populate frmCalendar.

Thanks!
 
S

Stuart McCall

jayjay21us via AccessMonster.com said:
I'm very new to dealing with DAO Recordset... I"m trying the following to
populate a form with unbound text fields... I have 10 unbound text boxes..
D0
thru D9. I want the result of the recordset to populate the unbound text
boxes. But I don't know how to do so..I search and googled, but I'm
confused.
. So I got this to work to at least it tells me I'm going in the right
direction... Any help would be appreciated....


Option Compare Database
Sub DisplayWeekly()
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("SELECT DocketID, PLFirst, PLLast FROM
HearingSchedule", dbOpenDynaset)
Do While Not rs.EOF
Debug.Print rs![DOCKETID]; rs![PLFIRST]; rs![PLLAST]
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
End Sub

I did the Debug.Print to see if it was returning what I want.. and it
is... I
just can't get update the script to populate frmCalendar.

Thanks!

If this code exists in the unbound form's module, all you need to do is
replace this line:

Debug.Print rs![DOCKETID]; rs![PLFIRST]; rs![PLLAST]

With these three lines (I'm guessing at your control names, obviously) :

Me.TxtDocketId = rs![DOCKETID]
Me.txtPlFirst = rs![PLFIRST]
Me.txtPlLast = rs![PLLAST]
 
M

Marshall Barton

jayjay21us said:
I'm very new to dealing with DAO Recordset... I"m trying the following to
populate a form with unbound text fields... I have 10 unbound text boxes.. D0
thru D9. I want the result of the recordset to populate the unbound text
boxes. But I don't know how to do so..I search and googled, but I'm confused.
. So I got this to work to at least it tells me I'm going in the right
direction... Any help would be appreciated....


Option Compare Database
Sub DisplayWeekly()
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("SELECT DocketID, PLFirst, PLLast FROM
HearingSchedule", dbOpenDynaset)
Do While Not rs.EOF
Debug.Print rs![DOCKETID]; rs![PLFIRST]; rs![PLLAST]
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
End Sub

I did the Debug.Print to see if it was returning what I want.. and it is... I
just can't get update the script to populate frmCalendar.


What do you want in the 10 text boxes?

Mayve the recordset has up to 10 records and you want the
three fields concatenated into each text box???

If so, replace the Debug line with:

Me("D" & K) = rs!DOCKETID & rs!PLFIRST & rs!PLLAST
K = K + 1
 
J

jayjay21us via AccessMonster.com

I don't think the unbound form has a module?? The current dao code is in a
module called Gobal Code.. It's called the frmCalendar is activited.

The only text boxes on the form are unbound named

D0
D2
D3
D4
etc..

There are only 10 unbound boxes. There would be only 10 records that could
be retrieved by the form with the unbound boxes. The only text boxes on the
form are D0, D1, D2,etc...

So it would be ...

[DocketID] [Pl First][PlLast]
D0 - 1111111 Tim Brown -
D1 - 222222 Jane Green
D3 - 333333 Cheryl Crow

I can't get the DAO to populate the D0, D1, D2....

Stuart said:
I'm very new to dealing with DAO Recordset... I"m trying the following to
populate a form with unbound text fields... I have 10 unbound text boxes..
[quoted text clipped - 25 lines]

If this code exists in the unbound form's module, all you need to do is
replace this line:

Debug.Print rs![DOCKETID]; rs![PLFIRST]; rs![PLLAST]

With these three lines (I'm guessing at your control names, obviously) :

Me.TxtDocketId = rs![DOCKETID]
Me.txtPlFirst = rs![PLFIRST]
Me.txtPlLast = rs![PLLAST]
 
J

jayjay21us via AccessMonster.com

HI.. It's giving me an error messgae.. "Invalid use of Me Keyword"

Marshall said:
I'm very new to dealing with DAO Recordset... I"m trying the following to
populate a form with unbound text fields... I have 10 unbound text boxes.. D0
[quoted text clipped - 20 lines]
I did the Debug.Print to see if it was returning what I want.. and it is... I
just can't get update the script to populate frmCalendar.

What do you want in the 10 text boxes?

Mayve the recordset has up to 10 records and you want the
three fields concatenated into each text box???

If so, replace the Debug line with:

Me("D" & K) = rs!DOCKETID & rs!PLFIRST & rs!PLLAST
K = K + 1
 
M

Marshall Barton

That can only mean that the code is in a standard module,
not in the form's module. Try using the full form
reference:

Forms![name of the form].Controls("D" & K) = rs!DOCKETID &
rs!PLFIRST & rs!PLLAST

You really should provide these little details so we have
some idea about what we're working with. And you still
haven't said what is supposed to end up in the text boxes or
why you need 10 of them.
--
Marsh
MVP [MS Access]

HI.. It's giving me an error messgae.. "Invalid use of Me Keyword"

Marshall said:
I'm very new to dealing with DAO Recordset... I"m trying the following to
populate a form with unbound text fields... I have 10 unbound text boxes.. D0
[quoted text clipped - 20 lines]
I did the Debug.Print to see if it was returning what I want.. and it is... I
just can't get update the script to populate frmCalendar.

What do you want in the 10 text boxes?

Mayve the recordset has up to 10 records and you want the
three fields concatenated into each text box???

If so, replace the Debug line with:

Me("D" & K) = rs!DOCKETID & rs!PLFIRST & rs!PLLAST
K = K + 1
 
J

jayjay21us via AccessMonster.com

There are 10 unbound boxes. There would be only 10 records that could
be retrieved by the form with the unbound boxes. The text boxes on the
form are D0, D1, D2,etc... Each box would retreive one record of the
following..which would be based upon a specific date...

[DocketID] [Pl First][PlLast]
D0 - 1111111 Tim Brown -
D1 - 222222 Jane Green
D3 - 333333 Cheryl Crow

Marshall said:
That can only mean that the code is in a standard module,
not in the form's module. Try using the full form
reference:

Forms![name of the form].Controls("D" & K) = rs!DOCKETID &
rs!PLFIRST & rs!PLLAST

You really should provide these little details so we have
some idea about what we're working with. And you still
haven't said what is supposed to end up in the text boxes or
why you need 10 of them.
HI.. It's giving me an error messgae.. "Invalid use of Me Keyword"
[quoted text clipped - 13 lines]
 
J

jayjay21us via AccessMonster.com

The specific date would be retrieved with a WHERE statement.

Marshall said:
That can only mean that the code is in a standard module,
not in the form's module. Try using the full form
reference:

Forms![name of the form].Controls("D" & K) = rs!DOCKETID &
rs!PLFIRST & rs!PLLAST

You really should provide these little details so we have
some idea about what we're working with. And you still
haven't said what is supposed to end up in the text boxes or
why you need 10 of them.
HI.. It's giving me an error messgae.. "Invalid use of Me Keyword"
[quoted text clipped - 13 lines]
 
J

jayjay21us via AccessMonster.com

That worked!!! Thanks!!!!
There are 10 unbound boxes. There would be only 10 records that could
be retrieved by the form with the unbound boxes. The text boxes on the
form are D0, D1, D2,etc... Each box would retreive one record of the
following..which would be based upon a specific date...

[DocketID] [Pl First][PlLast]
D0 - 1111111 Tim Brown -
D1 - 222222 Jane Green
D3 - 333333 Cheryl Crow
That can only mean that the code is in a standard module,
not in the form's module. Try using the full form
[quoted text clipped - 12 lines]
 
J

jayjay21us via AccessMonster.com

Ok... it works when there is a record for the date it's looking for, but when
I choose a date where there is no record, it just shows that last record that
did have a date.

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("SELECT DocketID, PLFirst, PLLast, DFFirst,
DFLast FROM HearingSchedule WHERE HearingDate = #" & Forms!Form4!D0 & "#",
dbOpenDynaset)
Do While Not rs.EOF
Forms![Form4].Controls("D" & K) = Format(rs!DOCKETID, "####-######") &
Chr(13) & Chr(10) & "PL-" & rs!PLFIRST & rs!PLLAST & Chr(13) & Chr(10) & "DF-
" & rs!DFFIRST & rs!DFLAST
K = K + 1

rs.MoveNext
Loop
rs.Close
Set rs = Nothing


Is there something that should be added to to clear something before it seach
for the next date??

Thanks again!

Marshall said:
That can only mean that the code is in a standard module,
not in the form's module. Try using the full form
reference:

Forms![name of the form].Controls("D" & K) = rs!DOCKETID &
rs!PLFIRST & rs!PLLAST

You really should provide these little details so we have
some idea about what we're working with. And you still
haven't said what is supposed to end up in the text boxes or
why you need 10 of them.
HI.. It's giving me an error messgae.. "Invalid use of Me Keyword"
[quoted text clipped - 13 lines]
 
D

David W. Fenton

I"m trying the following to
populate a form with unbound text fields

Why? I can count on the fingers of one hand the number of unbound
forms that I've populated from recordsets in the dozens of apps I've
created since I started developing in Access professionally back in
1996. Sure, I use unbound forms as dialogs all the time, and often
to collect data that I use for other purposes (not writing them
directly to a table), but hardly ever is there a need to populate an
unbound form from a recordset.

In many, many cases, it's a symptom of trying to make things overly
complicated, likely because you don't know the simpler way to do
things, i.e., the Access way (as opposed to the kind of things you
have to do in other programming environments, which don't offer
bound data by default).

Now, that's not to say that you don't have a case where it makes
sense to populate an unbound form from a recordset.

But you should ask yourself if you really have chosen the easiest
way to accomplish your task.
 

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