Do while loop Problem!!!Need Help....

andyrohith

New member
Local time
Today, 06:50
Joined
Oct 18, 2009
Messages
5
Hai All,

I am doing a barcode generator program in access and process is in the form i have a text box where i can enter an item number and the barcode is generated in a report.Now the criteria is ,suppose if the item number i entered has 5 pieces then it must write same 5 barcodes in the report.This is my code

Private Sub Command4_Click()
Dim Counter As Integer
Dim Temp As Integer


If DCount("*", "Table1", "Field1 like '*" & Me.itnumber & "*'") = 0 Then
'no records, display message
MsgBox "There are no records that meet your search criteria"
Me.itnumber.SetFocus
Temp = Quanlity
Exit Sub
Else
Counter = 0
Do While (Counter <= Temp)

DoCmd.RunSQL ("INSERT INTO table2 ([Number]) VALUES (itnumber)")
Counter = Counter + 1
Loop
End If
If (Counter > Temp) Then
DoCmd.OpenReport "Hadabah", acViewPreview, , "Number like '*" & Me.itnumber & "*'"
End If
End Sub

The technique iam using is to get the item number from Table1 and insert in another table named Table2 with respect to the quantity.And then get it in the report.But iam getting them only once in the report.I know there's some problem in loop structure.Pls help with this iam new to vb.

Thanks,

Andrew....
 
You REALLY made a column in a table named "Number"? That's a bad idea.

Your code is quite difficult to read but from just a cursory glance, I'd say you need to check what the value on "quanlity" (did you really mean to name it that?) is via a debug.print or msgbox. Make sure you have the line "Option Explicit" at the top of the module this code is located in. If stuff starts breaking, you'll have your answer.

Have you stepped through this code with a break point, validating the value of each variable at each step?
 
Hai,

The problem is with this "Temp = Quantity" the value doesnt move to the temp.My suntax is wrong probably..anyways suggestions will be appreciated

Thanx,

Andrew...
 
Hai All,

Iam Having Problem with checking the value of Quantity from the table and then moving it to a temporary field.It would be gud if i get an example.

Thanx,

Andrew..
 
Hai,

The problem is with this "Temp = Quantity" the value doesnt move to the temp.My suntax is wrong probably..anyways suggestions will be appreciated

Thanx,

Andrew...

What quantity? There is no variable or anything in this code that should give quantity a value

If I am guessing right...
Temp = Quanlity
Exit Sub
Else
Counter = 0
Do While (Counter <= Temp)

You want to loop each record found... In which case your temp=quantity will not even be executed because it is in the other IF branche.

IF I am guessing right your code should look more like:
Temp = DCount("*", "Table1", "Field1 like '*" & Me.itnumber & "*'")
If Temp = 0 Then
followed by "the rest"

Remarks:
1) Use the code tag (#) on top of the post bar when your posting code
2) itnumber, sounds like a number field, you sure about '*123*' ??
3) Why push your data into what seems to be a temporary table, instead just run your report of the main table without problems
 

Users who are viewing this thread

Back
Top Bottom