Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Basic Loop Command


Hi ppl,

Can anyone tell me what command I need to use to initiate a loop?
Let's say I have a MsgBox command I want to loop 5 times, with a delay of 5 seconds for each loop. How could I do that?
Thanks!







Added green "resolved" checkmark - Hack




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Loop A Command
I have a SS with Subtotals on it that Subtotals a "Count" of items based on the City they are in. I want to run a loop that lets me "Find" each subtotal count and copy that info to a summary sheet. Right now I have the Macro doing a "Find" that looks down the "City" column and "Finds" the Word "Count". I then have the Macro copy that data, (City Name), and the cell next to it which is the actual count of items for that city. Then the Macro paste's that data to a separate worksheet tab.

I can make the Marco do all that I want once. Is there a way to do this so the macro will repeat itself until it runs all the way to the end of the column and then stop? The last line will always say "Grand Count"

I understand the concept of the loop statement but not how to write them effectively or if it will even work for this scenario


Thanks.

Loop Command
hey i want to know how the loop command work i have a command and i want to work always, what is the code that i have to use?

Using The SendKeys Command In A Do While Loop
I have a spreadsheet with two columns, the first column is an indicator and second column contains sparse data. I need to copy the values in second column down the column until the indocator column is blank. As the value in the second column changes, I want to copy the new value.
I can't get the sendkeys command to work while inside the Do While Loop.

Sub CopyTest2()
Range("B4").Select
ActiveCell.Offset(1, -1).Range("A1").Select
Do While ActiveCell <> ""
ActiveCell.Offset(-1, 1).Range("A1").Select
Selection.Copy
SendKeys "+(<End><Down><UP>)"
ActiveSheet.Paste
SendKeys "{Enter}"
SendKeys "{End}{Down}"
ActiveCell.Offset(1, -1).Range("A1").Select

Loop

End Sub

Command Button? And For Loop?
1. How do you add a picture to a command button...

I went to picture property and added an icon thern when that didnt work I tried adding a bitmap......

So whats the trick here?


2. I want to on click event of a command button add 1 to a text box

NOTE: User may choose to type a starting value in the textbox thus the button thus the click event must check to see the Value entered by the user if any then if so add 1 to it.

vbMarkO

Break Loop Command?
is there a command to break a loop?
for example


VB Code:
Do Until breaker = True    If IOst = "Out" Then        If ordn = rsB.Fields("loadNO") Then            breaker = True        End If    ElseIf IOst = "In" Then        If ordn = rsB.Fields("loadNI") Then            breaker = True        End If    ElseIf IOst = "Start" Then        MsgBox "You Can Not Move the Starting Balance", vbCritical, "Error"        Exit Sub    Else        MsgBox "Read in Error", vbCritical, "Error"        Exit Sub    End If    rsB.MoveNext    If rsB.EOF And Not breaker Then        MsgBox "Order Number Does Not Exist", vbCritical, "Error"        Exit Sub    End IfLoop


currently I have to throw a "rsb.moveprevious" after the loop, but if I had a "break loop" commany I could modify it to work better

Loop Break On Keyboard Command
I am writing a basic program in VB6 that moves the mouse around the screen on a coordianate system and uses a function to click the mouse after it has been moved. This is done in a loop for hundreds of coordinates. If there is an error, I want to be able to stop the program. Ctrl+Break dosent work, and ALT+CTRL+DEL will popup, but I can't click on my app from the list of programs to end the task because the mouse and the focus get changed in 10th's if a second. Is there a way that I can break out of this loop and exit or stop my program with the push of a single designated key on the keyboard?

Anyones help is greatly appreciated.

Thanks,

Keith
kbert@optonline.net

Exit Loop Using Command Button
I am writing a program which has a loop which updates the value of a text box based on information its receiving from the serial port. Is it possible to jump out of this do loop using a command button click. It doesn't seem to register that I've clicked the exit command button until the loop has ended.

Query Using A Do While Loop Command - Resolved
Hiya

I have a combo box with a list of dat and I have a text box.

I need to add in functionality to enable a user to input a letter (or more than one letter) into the text box using a do while loop to do a search in the combo box to find an index position greater than the text entered.

Can anyone assist me with this please?

Thanks

Taz

Stopping Loop With Command Button
I want to do a
Do Until Loop
stopping when a command button is clicked.

Using Command Button To Break Out Of A Loop
I have a loop that displays records from a database, does some "stuff" that lasts about 2-3 seconds, and then advances to the next record. As this is happening I am displaying information about the current record in several text Boxes. My problem is that I need the ability to stop this on command. I have a Stop button, but once the loop has started running, I am not able to press the stop button. Any ideas on how to accomplish this? I would use a Thread in other languages, but with my limited knowledge of VB I don't know how to do this (I don't think they are supported??).

Any help would be appreciated.

Building A Command Line (for/next Loop)...
VB Code:
For i = 0 To chkConfig.Ubound    PM1 = PM1 & IIF(chkConfig(i).Value, chkConfig(i).Tooltip, "no") & " "Next Shell "C:YourProgram.exe " & PM1, vbNormalFocus

Basic Loop Question
Code:
Private Sub Form_activate()
If cdkey.text = "43243" Then
continue.enabled = True
Else
Doevents: Loop
End If

You know how when u register a program, there is a text box where u insert the key, and a disabled button? Then, once the cdkey is correct, it enables the button?

So.. how would i do that?

What is wrong with the code that i have above? Thanks!

Sense Command Button State From Within A For/next Loop
I have a program that is controlling a moving mechanism via the Com1 port. I am sending out movement commands as a function of time but would like to be able to stop this process by using a stop button in the GUI. How do I monitor the state of this command button from within the movement communication subroutine so that I can send out a command to stop the movement should that become necessary? So far I can only activate the stop command button when the movement subroutine for/next loop has finished.

How To Make A Command Button Stop A Loop.
Ok so I have cmdstart and cmdStop. cmdstart has a loop, so it keeps on going, on and on. How would I make it so cmdstop stops the loop?

Can I Create A Loop On One Command Button And Stop On Another?
Ok... can i make a loop when you press command1 and then have it stopped when you press command2.

I'm not worried about any lagg or w/e... but i'm curious if this works. I dought it'll lagg since i have two processors, but jw if this is possible.

Abort Loop When Hitting Command Button
Hello!
In my app I'm using a rather slow loop, which takes a lot of time. I'm using a form with a progressbar to show how much time it's left, but I would like to have a commandbutton which the user could press to abort the loop -a cancel button.

I'm not sure how to do this, since pressing a button triggers a new event, and my app is bussy carriyng out the event with the loop.

If you know how to do this, please help me!
Pentax

How To Exit A While Loop In Visual Basic 6 0
How to exit a while loop in Visual Basic 6.0

Basic VB Macro Loop For Pasting Screen Shots
I am very new to VB and know a little bit about macros.
I want to automate the pasting of screen shots from a program to MS power point and then create a new slide. To which the paste function happens again.
I have copied the original recorded macro, how do I create a loop of this for say 25 steps (can this number be made a variable).

Sub Macro2()
'
' Macro recorded 1/11/2005 by me
'

ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=4, Layout:=ppLayoutBlank).SlideIndex
ActiveWindow.View.Paste
End Sub

Cheers

BASIC Question- Please Help {processing Controls While Loop Is Running}
Hi,

How can I have access to controls on a form WHILE a loop is being executed via another control?

I have a VB form with Command buttons, radio buttons and check boxes etc.

The command1 button starts to Rotate (Animate) a Picture using a Do-Loop. I would like to be able to do other things (like also change color of the image) by clicking radio buttons WHILE ithe image is rotating. But while the Do-Loop is running, I cant do anything else. It wont let me click anything.

My Head Is Hurting (complicated Yet Basic Loop Question ... I Hope)
NOTE: This is very complicated, yet basic

I have two Sub's which each have two Loops in them, the first sub calls the second sub and then calls itself again. I have simplified this down to show you my problem. (if you bear with me this should make a little sense)

VB Code:
Sub1()For Each varA in varB 'we'll call this loop1    varC = 0    Do Until varC = varD 'we'll call this loop2        varX = varA        txtA = txtA & vbCrLf & vbTab & varA        varC = varC + 1    Loop 'end of loop2    varD = varD + 1    Call Sub2(varX)    call Sub1(varX)Next 'end of loop1End Sub Sub2()For Each varE in varF 'we'll call this loop3    varG = 0    Do Until varG = varD 'we'll call this loop4        txtA = txtA & vbCrLf & vbTab & varE        varF = varF + 1    Loop 'end of loop4Next 'end of loop5End Sub



Basically I got my two subs working, they outputted values to a text box. I then wanted the text in the textbox to be indented, the amount which it is indented varies each time.

I thought a loop could handle this, (i already had a loop in each of my subs) so I added a do...until loop inside a For loop (for each sub).

Now in theory what I want to happen
loop1 executes
resets loop2's counter
loop2 executes and adds a tab
loop2's counter increases until it has met its target
loop3 executes
resetes loop4's counter
loop4 does as loop2 did
loop3 ends and back to loop 1

I suppose what I am asking is the logic ok behind it, and is the line that adds my tabs ok?

I know this sounds very very complicated, but anyhelp you can give me would be great.

TIA

At Command In Visual Basic
i write a project to send sms using at command this is the code

MSComm1.Output = "at+cmgf=1"
MSComm1.Output = vbCrLf
MSComm1.Output = "at+cmgs="
MSComm1.Output = "0506528440"
MSComm1.Output = vbCrLf
MSComm1.Output = "hello"
mscomm1.output=CTRL+Z

so my question is how to write CTRL+Z as ascii code or if you have other idea

Play Command (GW BASIC)
Any body familiar with QBASIC or GW BASIC may know about the Play command ?
Ie. a function requesting for 2 parameters viz : Frequency & Duration
Once this line get executed the sound corresponding to the Frequency specified, will be played by the system speaker.

Eg: Play (700, 20) ' this line will play the sound having 700 Hz for a period of 20 seconds

Is there a Similar function or any thing in VB (I am not interested in MIDI file players etc)
Srinika

Backcolr For Command!! Visual Basic
I want to change the color of order with API!!, I know well with visual BASIC, one can make it directly with the property backolor, but the problem that I cree the command already with createwindow, then I cannot use this method. I know that is possible to do that with the api sendmessage or another, but I do not arrive has to do it !!! , please help me to find a solution thank you very much, it very urgent, that is made moment that I test

Command Line And Visual Basic
hello

I need execute a visual program with command line parameter to automate some task. For example, if my executable file is "program.exe" I want to execute from a MS-DOS window the command "c:program.exe value1 value2" and in the program associate a variable called "param1" the first value and a variable called "param2" to the second value.

How can I get that parameters in Visual Basic?

Thanks for your help in advance, Eliseo Aznarte.

And sorry for my english ...

Visual Basic 6 Command Button
I am using VB6. I am trying to create a command button in a standared
executable form. When I type the following statement in a module window
"Begin VB.commandbutton command1", What I was expecting was that once I
typed VB. I should see the commandbutton property in the object browser as a
available property. It does not show up. What could be the cause of this?
Is there anything that I need to check in my references box in order to have
this property available. Any suggestions will be greatly appreciated. I
searched the archives for information on this, but I did not find anything
that addressed this issue.

Thank you for your help.
MT.

Visual Basic Voice Command
Anyone who knows how to create voice command in 2 ways.

     1. Voice as warning instead of messagebox.
     2. Voice command instead of click event or voice command using a robot.

Any help would be greatly appreciated.

Thank you.

Shell Command In Visual Basic Access
hello, i use a form in access to open several word, excel, pdf files

therefore i use
'RetVal = Shell(mycfil, VbNormalFocus)'

where mycfil si the application string + the document string

it works , biut i have 2 problems :
-VbNormalFocus does'n t give teh focus to the spreadsheet,wordfile ...
-when i have to open a second spreadsheet f.e. (while the first spreadsheet is still open) then the excel application starts for the second time , after ten times the excel application opens for the 10th time and so on ..

does somebody have a suggestion to do that in a better way ??

Command Line Option In Visual Basic
Is it possible to pass command line options to an application written in vb when you start the application ( as can be done in C/C++ ,java etc ). I normally store startup options in the registry and have my app read the entry as it starts up (form load event ) then delete the registry entry. I am wondering if there is any direct way of passing commandline options.

Thank you in advance.

Showing Command Codes From Visual Basic
While running a program, is there a way for you to list all of your computer commands as you do them? For example: let's say you click on a command button - it would show in a small window the code kinda like Private Sub Click_(). Not only would I want it to show me the code for stuff like that but also pre-programmed commands like if you highlight a certain cell in a Datagrid - what would be the command to do it in Visual Basic - even tho it wouldn't be listed as something you typed?
Is that a program you would have to buy extra?

Please let me know.
Thanks

Stephen

Quiting Visual Basic By Using A Command Button
This sounds really easy to do, and I know I have done this before(I admit it was in access), but how do I completely exit vb. All unload does for me is to unload the forms and return me to the form design page. I want the program to terminate completly.

sorry for the spelling in advance.

Visual Basic 4.0 And Command Line Arguments
I am using Visual Basic 4.0 to create executable CGI scripts, which despite the dated technology, works well. In order to streamline the number of executable files that are neccessary, it seems like a good idea to pass command line arguments to each program.

As an example, I collect data, and then proceed from compiled CGI Data1.exe to Data2.exe.

Instead, it seems like a great idea to call a Data.exe, followed by some parameter, hence: Data.exe 1, or Data.exe 2.

Using VB4.0, how do I pass parameters in this way? Does anyone know?

Thanks!

Shaun

Basic Delete Command Button (Access)
Not sure if this is the correct place to ask this or not. I am a MS Access 2003 newbie, I usually am doing PHP stuff.

I am helping a friend with a database form and want to do a basic delete record button.

I have all the other buttons working fine. new record, previous, next, last, save and close as they were all pretty easy to figure out with the macro thing.

Just can't figure out how to do the delete record one.

I assume in VB you have to put something in between this code.


Code:

Private Sub Delete_Record_Click()

End Sub



I would appreciate any help or direction to help.

Thanks!

Visual Basic - Command For Index Closing
Hi

I need to open an access database with multiple index in Visual Basic. This file contains CODE, NAME fields. First I took NAMEwise index and seek the approprate records. Thats working. Secondly I have tried to take the CODEwise index, then I got an error message "Row handle must be released". I think I want to close the first index before taking the second one. But I dont know the Command like SET INDEX TO in Visual foxpro to close the first index . Can you someone help me ?? It will be very thankful.

Thanks
-Subhash

Command Line Arguments In Visual Basic
Hi

Can someone provide me with an example for developing VB applications which accept command line arguments please ?

Thanks

Suhaib

Try To Run Shell Command To Excute Xcopy In Visual Basic
I am trying to run xcopy from Visual Basic using shell and it is not working. Any help is appreciated!

Shell "xcopy C:Documents and SettingssName*.* /E /F /G /H /K /O /Y c: emp"

Am I doing it right?

The sNAME is a variable name that was inputed by the user when I prompt them to put their user name beforehand. (sName = UserID.Text)

I took the variable sNAME out and put my name which is a valid folder on the system and ran the shell command from VB and it did not do anything. (it is supposed to copy everything from C:Documents and Settingsjatalife folder to c: emp.)

Do I need to use batch file to do the copy? If so how can send the USERNAME in the batch file to copy the correct directory for the user.

Use Shell Command To Sort File In Visual Basic
I have this trouble to use shell command to sort a simple text file from Visual Basic:

Here is the Visual Basic code:

Private sub CmdSort_click()
dim StrCommandLine as string
StrCommandLine=App.Path & "sortsum.bat"
shell strCommandLine, vbMinimized
end sub


The batch file "Zsortsum.bat" is following:
c:winntsystem32sort.exe &lt;c:smy.tmp&gt; c:sumdoc.srt

The problem is that I can not get the file
sumdoc.srt generated ( or created) after I executed the Visual basic program( there is not error message in VB) . I can have the sumdoc.srt file generate if I use the batch file in DOS system. Could you tell me why? Thanks a lot!!!

Visual Basic 6: Executing File From Command Button
I need to a code to open a .doc file (with its default program e.g Microsoft Word).. when you click on a command button...

Can anyone help?

Thanks in advance.

How To Run Pikzip Command In Visual Basic For Multi Files?
I have a .bat file which contains the following line

pkzip -a -sPassword fin.zip @STMN.txt STMN.txt SGN.txt SVN.txt EQN.txt SPN.txt LSN.txt LSMN.txt WPGN.txt WPN.txt WPSN.txt

which means: it creates a zip file named fin.zip with password sPassword and contains all the above txt files.

Can you show me how can I include the above command in VB?
I do not want to run .bat file , I'mm thinking "Shellexecute hWnd,"open" pikzip.exe etc..."

Regards
Michael


Michael Sakellis
Athens-Greece

Command Line Build Of Embedded Visual Basic
Does anyone know how to run "make" from the command line? When I do "EVB3 /?" it pops up a dialog that says you can use "/make" just like in VB but it doesn't seem to work.

Shell Command Or Equivalent For Embedded Visual Basic
Can anyone get the Shell command to work on Embedded Visual Basic? If so, could you give me an example of how to per say, create a button that when clicked it will start the calendar application (without ending the application). I have the following:


Private Sub Command8_Click()
    Dim RetVal As Double
    RetVal = Shell("c:windowscalendar.exe", 3)
End Sub

But when I run it, it says that :
An error was encountered when running the program: Variable is undefined: 'Shell'

So am I doing something wrong or is Shell not supported in Embedded Visual Basic? If it isn't, does anyone know of the equivalent in Embedded Visual Basic? Or am I not doing something right? Do I have to set up special references in order to use this command? I am using Microsoft eMbedded Visual Basic 3.0 For Embedded Windows Development and am using the emulator on the SDK.

Any comments on this would be greatly appreciated.

thanks,
Aldo


 

Basic Error Check Question With Command Buttons
I have a program in VBA and I am using 2 command buttons. With the first commad button I am creating a dynamic array where it will create a matrix in excel. I am doing certain error checks where if the user has not clicked on the first command button for an array to be stored the second command button should warn the user that they have to enter values by clikcing on the first button. My question is if the user clicks on the second command button before clicking on the first command button to initially create an array, how does it pick up that the first command button was not clicked by the user and that no values for the array was created?

Visual Basic 6 Shell Command And Program Located In Unc Path.
I running this command:

Shell ("\serverHDRIquick3270Quick3270 ver 3.92.msi")

But I get:
"
Run-time error '5':
Invalid procedure call or argument.
"

I was wondering how I could run a program located in an unc path.

ExitProcess API Works Well In Visual Basic IDE But Not In Command Line Mode???
Please help, this is urgent....

I am writting a VB program which is called from my java program. Because the java program needs to know whether there is any problem when the VB prog run. Hence I use ExitProcess API in VB prog to return exit code to Java prog (0 for ok and >0 for error). When I try to test VB program, this function works correctly (it closes VB IDE ). But when I try to run it in Java program, it halt, or rather, not halt but stop at the ExitProcess API. Then I try to run VB program in command line mode (C:ProjectsMyVB.exe), it still stops at ExitProcess API. All tasks and functions before this function work very well in any case.

Please help. Thanks a lot.

Call Visual Basic Program (active Exe) From Command Line (passing A Parameter)
hi experts,

i created an active exe VB6 apps that accepts a parameter. it prints a report using the parameter as a condition. how can i call the apps from other apps? i tried running the exe with a parameter but its not doing anything.

any help would be greatly appreciated.

regards.

ann

Visual Basic Problem "Do Without Loop"
Okay i've got this piece of code thats not working. Each time i run it it says, do without loop.


VB Code:
Private Sub Form_Load()    Dim Day As Date    Dim Correct As Boolean    Dim index As Integer        Correct = False    Do While Correct = False        Day = InputBox("Please enter todays date, in this fasion 01/01/2006")        If Len(Day) <> 10 Then            MsgBox ("The date you entered wasn't the correct length, please reenter it")        Else            Correct = True        End If        Do While index <> Len(Day)        If Mid(Day, index, 1) > Chr(64) Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "!" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "@" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "#" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "$" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "%" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "^" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "&" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "*" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "(" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = ")" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "_" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "-" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "+" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "=" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "|" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "?" Then            MsgBox ("Dates don't contain letters")            Correct = False        ElseIf Mid(Day, index, 1) = "|" Then            MsgBox ("Dates don't contain letters")            Correct = False        Else            Correct = True        End If        Loop            Extra(1).TodaysDate = DayEnd Sub


Now i've checked to see if the loop was in an if satment, but its not.

So can anyone help me?

Do/Loop,Need To Nest Another Loop To Check For Duplicates(FIGURED IT OUT)
check it out, what i am doing is reading in from my DB, customer orderID's. The table that i am reading from will have multiple OrderID's and some will be duplicates. That all fine but i dont want to have order number 115 show up 3 times when 1 time would be enough. This is the loop that i am using and am loading the values in the the combo box. What i would like to do, is once i hit this line of code

Combo2.List(i) = ![OrderID]

then do either a for each , or for next loop to walk through the contents of combo2 and check for a duplicate, if a duplicate is found i would like to take the current orderID that was just loaded out of the combo2 box. I have tried a for each loop but i am not geting the syntax correct of what exactly i am trying to search through. That where you guys come into play. could some one please help with this problem

Do Until .EOF
   Combo2.List(i) = ![OrderID]
   i = i + 1
   .MoveNext
Loop

This is what i would like to accomplish.
DO Until .EOF
    load orderID into combo box
        For Each orderID in combo box
             If duplicate found then
                  delete current entry
             end if
         next
     continue loading orderid's
loop



Edited by - lmf232s on 7/24/2003 1:59:30 PM

Game Loop Without Creating An Endless Loop?
im trying to setup a loop for my game to draw the scene as many times as it can each second, however, i end up simply creating a loop that stops basically everything. timers do not function, command buttion clicks are ignored, not what i wanted.

so, then i tried a timer, but even at a setting of 1 it was too slow for my purpose. (unless you want to play the game limited to 10 FPS ) so, is there any faster timer system, or a differnt loop system i didnt think of?
thanks

Creating A Dataset In A Loop (i.e. For .....next Loop)
Dear Expert,

I'm having problems creating a dataset in a for __ next loop which I intend loading into a crystal report writer.

Please provide me with a sample code to perform the above.

Thanks

Loop The Loop: Adding List Item And Sub-items Assigned To Items.
Hello there,

below are the codes i've written to record all the items (which are qnsID) in list box (List1) into qnsdata_table.


Code:
Private Sub Command6_Click()
Dim x As Integer
Dim y As Integer

x = List1.ListCount
y = 0

rst.Open "SELECT * from qnsdata_table", cn, adOpenDynamic, adLockOptimistic

Do While Not y = x
rst1.Open "SELECT qnsdataID from autonumber", cn, adOpenDynamic, adLockOptimistic
rst.AddNew
rst!qnsDataID = "qd" & Right("000000" & CStr(CInt(rst1!qnsDataID) + 1), 6)
rst!qnsID = Me.List1.ItemData(y)
rst.Update
rst1.Close
rst1.Open "UPDATE autonumber SET qnsdataID = qnsdataID +1", cn, adOpenDynamic, adLockOptimistic
y = y + 1
Loop

rst.Close
End Sub


The problem is that for each item (qnsID) there are several assigned (ansID) and i need them to be recorded along with the qnsID, into qnsdata_table.
______________________________
| qnsdataID | qnsID | ansID |
-----------------------------------
| qd0001 | qns0002 | ans0012 |
| qd0002 | qns0002 | ans0016 |
| qd0003 | qns0002 | ans0001 |
------------------------------------

In this case, should i have another Do While Loop within the current Loop, to find out how many 'ansID' there are which are assigned to each 'qnsID'.

I've tried


Code:
rst2.Open "SELECT Count(ansID) AS ansID_count FROM ans_table where....(conditions)

Me.Text2 = rst2!ansID_count '(ive no idea where to store the count) value)

a = Me.Text2 '(shift value into variable a)
b = 0
and here goes another loop, but it didn't work.

Need some advice and comments from you guys =)

Thanks a million.

Astrov

Copyright 2005-08 www.BigResource.com, All rights reserved