PC Review


Reply
Thread Tools Rate Thread

Append Table with Loop

 
 
=?Utf-8?B?RG9yY2k=?=
Guest
Posts: n/a
 
      8th Mar 2005
I'm trying to populate a table with a nested loop, but nothing happens when I
run it. What's wrong with this picture? (Let me know if the following code
is not self-explanatory.) Thanks for your help.

Function FillLink()
Dim D, Q As Single
Set db = CurrentDb
Set rs = db.OpenRecordset("Dept-Question Link Table")
For D = 1 To 40
For Q = 1 To 96
rs.AddNew
rs!LD_Num = D
rs!LQ_Num = Q
Next Q
Next D
rs.Close
End Function

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Mar 2005
"Dorci" <(E-Mail Removed)> wrote in message
news:FEB79D96-BEBF-47E2-BAB3-(E-Mail Removed)
> I'm trying to populate a table with a nested loop, but nothing
> happens when I run it. What's wrong with this picture? (Let me know
> if the following code is not self-explanatory.) Thanks for your help.
>
> Function FillLink()
> Dim D, Q As Single
> Set db = CurrentDb
> Set rs = db.OpenRecordset("Dept-Question Link Table")
> For D = 1 To 40
> For Q = 1 To 96
> rs.AddNew
> rs!LD_Num = D
> rs!LQ_Num = Q
> Next Q
> Next D
> rs.Close
> End Function


There's no call to rs.Update, so the new record isn't saved. Try this
inside your loop:

rs.AddNew
rs!LD_Num = D
rs!LQ_Num = Q
rs.Update

Incidentally, be aware that this statement:

> Dim D, Q As Single


.... declares on Q as Single. D is a Variant, because you didn't declare
its type.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)



 
Reply With Quote
 
=?Utf-8?B?RG9yY2k=?=
Guest
Posts: n/a
 
      8th Mar 2005
Dirk,
Thanks for the reminder about the "rs.Update" statement. That worked
perfectly! I also corrected the Dim statement as you suggested, but I've
always been under the impression that you could declare variable types in one
fell swoop that way.

Thanks again for your prompt response. It's very much appreciated!

"Dirk Goldgar" wrote:

> "Dorci" <(E-Mail Removed)> wrote in message
> news:FEB79D96-BEBF-47E2-BAB3-(E-Mail Removed)
> > I'm trying to populate a table with a nested loop, but nothing
> > happens when I run it. What's wrong with this picture? (Let me know
> > if the following code is not self-explanatory.) Thanks for your help.
> >
> > Function FillLink()
> > Dim D, Q As Single
> > Set db = CurrentDb
> > Set rs = db.OpenRecordset("Dept-Question Link Table")
> > For D = 1 To 40
> > For Q = 1 To 96
> > rs.AddNew
> > rs!LD_Num = D
> > rs!LQ_Num = Q
> > Next Q
> > Next D
> > rs.Close
> > End Function

>
> There's no call to rs.Update, so the new record isn't saved. Try this
> inside your loop:
>
> rs.AddNew
> rs!LD_Num = D
> rs!LQ_Num = Q
> rs.Update
>
> Incidentally, be aware that this statement:
>
> > Dim D, Q As Single

>
> .... declares on Q as Single. D is a Variant, because you didn't declare
> its type.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Mar 2005
"Dorci" <(E-Mail Removed)> wrote in message
news:334CEFF2-36FF-4A10-81BF-(E-Mail Removed)
> Dirk,
> Thanks for the reminder about the "rs.Update" statement. That worked
> perfectly! I also corrected the Dim statement as you suggested, but
> I've always been under the impression that you could declare variable
> types in one fell swoop that way.


Nope, not in VB/VBA. Feel free to check it if you like.

Dim V, S As String
Debug.Print TypeName(V), TypeName(S)

> Thanks again for your prompt response. It's very much appreciated!


You're welcome.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Brendan Reynolds
Guest
Posts: n/a
 
      8th Mar 2005

"Dirk Goldgar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Dorci" <(E-Mail Removed)> wrote in message
> news:334CEFF2-36FF-4A10-81BF-(E-Mail Removed)
>> Dirk,
>> Thanks for the reminder about the "rs.Update" statement. That worked
>> perfectly! I also corrected the Dim statement as you suggested, but
>> I've always been under the impression that you could declare variable
>> types in one fell swoop that way.

>
> Nope, not in VB/VBA. Feel free to check it if you like.


Unless it's VB.NET. Whether VB.NET is or is not a version of VB is, of
course, a subject of some controversy ...

--
Brendan Reynolds (MVP)


 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Mar 2005
"Brendan Reynolds" <anonymous at discussions dot microsoft dot com>
wrote in message news:(E-Mail Removed)
> "Dirk Goldgar" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> "Dorci" <(E-Mail Removed)> wrote in message
>> news:334CEFF2-36FF-4A10-81BF-(E-Mail Removed)
>>> Dirk,
>>> Thanks for the reminder about the "rs.Update" statement. That
>>> worked perfectly! I also corrected the Dim statement as you
>>> suggested, but I've always been under the impression that you could
>>> declare variable types in one fell swoop that way.

>>
>> Nope, not in VB/VBA. Feel free to check it if you like.

>
> Unless it's VB.NET. Whether VB.NET is or is not a version of VB is, of
> course, a subject of some controversy ...


And not one I feel qualified to have an opinion on. <g> But if VB.Net
allows declarations like that, I can see how a .Netter could easily be
misled when writing VBA code.

I find it annoying that VBA doesn't support that sort of multiple
declaration, but I've gotten used to it.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
RD
Guest
Posts: n/a
 
      9th Mar 2005
On Tue, 8 Mar 2005 22:35:18 -0000, "Brendan Reynolds" <anonymous at
discussions dot microsoft dot com> wrote:

>
>"Dirk Goldgar" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> "Dorci" <(E-Mail Removed)> wrote in message
>> news:334CEFF2-36FF-4A10-81BF-(E-Mail Removed)
>>> Dirk,
>>> Thanks for the reminder about the "rs.Update" statement. That worked
>>> perfectly! I also corrected the Dim statement as you suggested, but
>>> I've always been under the impression that you could declare variable
>>> types in one fell swoop that way.

>>
>> Nope, not in VB/VBA. Feel free to check it if you like.

>
>Unless it's VB.NET. Whether VB.NET is or is not a version of VB is, of
>course, a subject of some controversy ...


Really? Huh! I'm at the very beginning of a project that is going
to involve a bunch of VB and VBScript coding (ASP and COM). One of my
colleagues has said that we may end up doing some stuff in .NET. He
says he's more of a C# guy and isn't used to VB but that the .NET
stuff doesn't bother him.

Is it really that different?

Thanks,
RD

 
Reply With Quote
 
RD
Guest
Posts: n/a
 
      9th Mar 2005
On Tue, 8 Mar 2005 18:49:55 -0500, "Dirk Goldgar"
<(E-Mail Removed)> wrote:

>"Brendan Reynolds" <anonymous at discussions dot microsoft dot com>
>wrote in message news:(E-Mail Removed)
>> "Dirk Goldgar" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> "Dorci" <(E-Mail Removed)> wrote in message
>>> news:334CEFF2-36FF-4A10-81BF-(E-Mail Removed)
>>>> Dirk,
>>>> Thanks for the reminder about the "rs.Update" statement. That
>>>> worked perfectly! I also corrected the Dim statement as you
>>>> suggested, but I've always been under the impression that you could
>>>> declare variable types in one fell swoop that way.
>>>
>>> Nope, not in VB/VBA. Feel free to check it if you like.

>>
>> Unless it's VB.NET. Whether VB.NET is or is not a version of VB is, of
>> course, a subject of some controversy ...

>
>And not one I feel qualified to have an opinion on. <g> But if VB.Net
>allows declarations like that, I can see how a .Netter could easily be
>misled when writing VBA code.
>
>I find it annoying that VBA doesn't support that sort of multiple
>declaration, but I've gotten used to it.


I've never been bothered by the need to be very explicit in
declarations. Keeps my head on straight. I find the loose-ness of
the "C syntax" languages almost impossible to read. I find myself
scratching my head, pointing at a chunk of code and asking, "What the
heck does THAT do?"

 
Reply With Quote
 
Brendan Reynolds
Guest
Posts: n/a
 
      9th Mar 2005
Like I said, it's a subject of controversy ... meaning that you'll get very
different answers to that question depending on who you're asking! :-)

I have no very strong feelings on the issue myself, but then it's easy to be
relaxed about it when you don't have a gazillion lines of 'classic' VB6 code
to convert and VBA is still supported. Ask me again a few years from now
when support for VBA is drawing to a close and I might feel differently
about it! :-(

--
Brendan Reynolds (MVP)


"RD" <(E-Mail Removed)> wrote in message
news:1110385870.e6887672a6c5ec4f369d27410fab578e@teranews...
> On Tue, 8 Mar 2005 22:35:18 -0000, "Brendan Reynolds" <anonymous at
> discussions dot microsoft dot com> wrote:
>
>>
>>"Dirk Goldgar" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> "Dorci" <(E-Mail Removed)> wrote in message
>>> news:334CEFF2-36FF-4A10-81BF-(E-Mail Removed)
>>>> Dirk,
>>>> Thanks for the reminder about the "rs.Update" statement. That worked
>>>> perfectly! I also corrected the Dim statement as you suggested, but
>>>> I've always been under the impression that you could declare variable
>>>> types in one fell swoop that way.
>>>
>>> Nope, not in VB/VBA. Feel free to check it if you like.

>>
>>Unless it's VB.NET. Whether VB.NET is or is not a version of VB is, of
>>course, a subject of some controversy ...

>
> Really? Huh! I'm at the very beginning of a project that is going
> to involve a bunch of VB and VBScript coding (ASP and COM). One of my
> colleagues has said that we may end up doing some stuff in .NET. He
> says he's more of a C# guy and isn't used to VB but that the .NET
> stuff doesn't bother him.
>
> Is it really that different?
>
> Thanks,
> RD
>



 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      9th Mar 2005
"Brendan Reynolds" <anonymous at discussions dot microsoft dot com>
wrote in news:(E-Mail Removed):

> I have no very strong feelings on the issue myself, but then it's easy
> to be relaxed about it when you don't have a gazillion lines of
> 'classic' VB6 code to convert and VBA is still supported. Ask me again
> a few years from now when support for VBA is drawing to a close and I
> might feel differently about it! :-(
>


Ten dollars to a rotten apple: it won't be .NET that is the current flavour
you are converting to by then..!


Tim F

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Append Query JJ Microsoft Access VBA Modules 1 1st Mar 2010 03:20 AM
Append query - Append to table with Autonumber field Boon Microsoft Access Queries 2 29th Jun 2009 06:23 PM
INSERT SQL to append recs frm another Table, NULL DATE append 30/1 accesshar Microsoft Access VBA Modules 2 14th Jan 2008 02:00 PM
Paste Append - I want to make a table of records that don't append =?Utf-8?B?Q0o=?= Microsoft Access Queries 1 5th Jul 2005 06:35 PM
loop through recordset and append data to a table Julie Microsoft Access VBA Modules 5 8th Oct 2003 12:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:57 PM.