Loop issue (1 Viewer)

Onlylonely

Registered User.
Local time
Today, 22:29
Joined
Jan 18, 2017
Messages
43
Hi Guys,

Appreciate if you could help me to solve this out.

For i = 1 To 5


CurrentDb.Execute "INSERT INTO Issuetbl (Part_Number, Serial_Number, Job_Number , Step, Character_ID) " & _
" VALUES ('" & Me.txtPN & "' , '" & Me.txtSN & " ', ' " & Me.txtJN & "', '1' , i )"

Next

Expectation: Part number, SN, JN and step is fix. ID is running number 1 to 5.For above coding, it cannot works.

P S J S ID
123 333 444 1 1
123 333 444 1 2
123 333 444 1 3
123 333 444 1 4
123 333 444 1 5
 

June7

AWF VIP
Local time
Today, 06:29
Joined
Mar 9, 2014
Messages
5,466
Don't put space between ' ". This will save value with a leading space. The trailing space in " ' should be dropped by Access but to be safe, don't use space there either.

For number type field, do not use apostrophe delimiters.

What does 'cannot works' mean - error message, wrong result, nothing happens?
 
Last edited:

moke123

AWF VIP
Local time
Today, 10:29
Joined
Jan 11, 2013
Messages
3,912
Code:
" VALUES ('" & Me.txtPN & "' , '" & Me.txtSN & " ', ' " & Me.txtJN & "', '1' , i )"
this may be resolving to a literal i instead of the value of i. The i is within the quotes.
try
Code:
" VALUES ('" & Me.txtPN & "' , '" & Me.txtSN & "','" & Me.txtJN & "', '1' ," &  i & " )"
and as june said if 1 is numeric datatype remove the single quotes.
I would also add "Next i" instead of just "next"
 

Users who are viewing this thread

Top Bottom