Insert a variable into the forms items name

  • Thread starter Thread starter Wiscow
  • Start date Start date
W

Wiscow

I am using DBpix. The way I can get a list of items with a picture is
by setting up a sinlge form and using code from DBpic's examples. In
the code exerpt it sets values for different sets of form items
advancing to the next for the next block of code.

If (Not rst.EOF) Then
fullpath = Folder & rst("DetailKey") & ".jpg"
If Dir(fullpath) <> vbNullString Then ActiveXCtl0.ImageViewFile
fullpath
Id0 = rst("DetailKey")
Name10.Value = rst("ItemName")
Category10.Value = rst("Category")
SubCategory10.Value = rst("SubCategory")
rst.MoveNext
End If

If (Not rst.EOF) Then
fullpath = Folder & rst("DetailKey") & ".jpg"
If Dir(fullpath) <> vbNullString Then ActiveXCtl1.ImageViewFile
fullpath
Id1 = rst("DetailKey")
Name11.Value = rst("ItemName")
Category11.Value = rst("Category")
SubCategory11.Value = rst("SubCategory")
rst.MoveNext
End If

I am trying to simplify it with one block of code and looping it. I
don't know how to inset the variable "Control" into each form item?
These are what I tried but imedietly get errors EX: Name & Control,
Name & ("Controll"), others.
I am a total beginner at VB but I have been able to pick my way through
most things.

Dim Control As Integer
Control = 0

Do Until Control = 6
If (Not rst.EOF) Then
fullpath = Folder & rst("MinOfFilename")
If Dir(fullpath) <> vbNullString Then
ActiveXCtl0.ImageViewFile fullpath
Id0 = rst("MinOfDetailKey")
Name0.Value = rst("ItemName")
Category0.Value = rst("Category")
SubCategory0.Value = rst("SubCategory")
rst.MoveNext
End If
End If
Control = Control + 1
Loop
 
Instead of
Name10.Value = ...
...
Name11.Value = ...

use something along these lines
Dim j As Long
...

j = 10
Do Until rst.EOF
...
Me.Controls("Name" & j).Value = ...
...
j = j + 1
Loop
 
Back
Top