Array in a For Loop

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

Guest

I am fairly new to this level of programming but I've managed to write the
following code where I'm attempting to use and array in a For Loop
unfortunately it gives me "Type Mismatch" error on the "For j = x(0) To x(8)"
on line 6.

I don't understand why it would not recognize the number sequence....?

CODE:
Public Function CheckPending(Name)
Dim x

x = Array("BanCk18", "BanCk36", "ChsCk18", "ChsCk36", "LmnCk18", "LmnCk36",
"MrbCk18", "MrbCk36", "PndCk18", "PndCk36")

For j = x(0) To x(8)
If j <> Name Then
PrdIN = j & "In"
Prdout = j & "Out"
If IsNull(Me.Controls(PrdIN).Value) = False Then
If IsNull(Me.Controls(Prdout).Value) = False Then
MsgBox "ATTENTION: There is a pending product that
needs to be completed prior to strating a new one.", vbExclamation, "Pending
Product"
Cancel = True
Me.Controls(PrdIN).Undo
Exit Function
End If
End If
End If
Next j

DoEvents

End Function
 
Hi,
use:

For j = lbound(x) To ubound(x)

you can reffer to your array element as x(j)
 
Thank you. That worked great although I did get stuck a few lines below (If
IsNull(Me.Controls(PrdIN).Value) = False Then) where I'm using the array to
create a field name to refer too on my form:

Run-time error '2465'
"BonProdDatabase can't find the field 'BanCK18in' referred to in your
expression."

FYI...
PrdIN = 'BanCK18in'
 
you have to make sure that control BanCK18in exists on a form, where you run
this code
 
BanCK18in is a Text Box name with a control source to a field in a table.
with (Me.Controls(PrdIN).Value) I'm hoping to retrieve the value from that
text box.
 
Back
Top