Append Table with Loop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Dorci said:
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,
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!
 
Dorci said:
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 said:
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 said:
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.
 
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
 
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?"
 
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! :-(
 
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
 
I'd be inclined to take that bet, Tim. It's really not very far away.
Mainstream support for VBA6 ends on 31 December 2008. (See
http://support.microsoft.com/default.aspx?scid=fh;[ln];lifedevtoolf
am). I think .NET will probably still be around in 3-and-a-bit years.


Interesting that MS Access is not in the list at all. I hope Microsoft
does not tell all the Access developers out there that it's not a
development platform! I note that VBA6 is due to decease in 2008 -- does
that mean the end of Access as we know and love it?

All the best


Tim F
 
Back
Top