Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random selection of EmpNames

Status
Not open for further replies.

christrawick

Programmer
Jul 15, 2002
23
0
0
US
Joe - I'm not being very successful at figuring out how to get the results of the code you suggested, into a form/report that can be viewed/printed. How do I direct the output of the Text1.(LostFocus) event to a form/report that I can view/print? Learning VB is a heck of a lot more difficult that anyone says.

Thanks
 
What type of report or form do you want it to display in?? Because you could display it really anywhere your want. Just put another text box on your form and call it whatever you want then in the code I gave you put this after
If dbs.recordcount > 0 then
txtWhatever.text = txtWhatever.text & Chr(13) & dbs!fieldnameyouwanttoadd.

that will at least let you know if you're getting some records. but tell me where you want to display it.

Hope this helps.
----------------
Joe
 
John,

Thanks. I just want to be able to dump the results out to another blank form for viewing/printing. As I look back into the code you posted, is there any modifications to it that need to be made so that the entire Access record (SSN, FirstName, LastName) will be pulled, or is it in place?
 
John,

Here is the modified code - I've attempted to dump the results into a Textbox, but I'm not getting any output.

Public mcnn As ADODB.Connection
Private dbs As ADODB.Recordset




Private Sub Command1_Click()
Dim EmplName As String
Dim Percent As Integer
Dim count As Integer
Dim random As Integer

count = 0
Percent = (Text1.Text / 100)
EmplName = Combo1.Text

While Not count = Percent
Randomize
random = (Rnd * 100)

Set mcnn = New ADODB.Connection
mcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\autochooser.mdb ;Persist Security Info=False"
mcnn.Open

Set dbs = New ADODB.Recordset
dbs.CursorType = adOpenKeyset
dbs.LockType = adLockOptimistic
dbs.Source = "SELECT * FROM tblEmployers" & _
"WHERE EmployerName = '" & EmplName & "' and fieldauto = " & random & ""
Set dbs.ActiveConnection = mcnn
dbs.Open

If dbs.RecordCount > 0 Then
Text1.Text = Text1.Text & Chr(13) & dbs!EmplName

'Display all your info here
End If
dbs.Close
mcnn.Close
Wend

End Sub
 
You just need to use this to get all records:

variable = dbs!fieldname (do this for all fields you want and make sure it's after th .recordcount)

do you think you might want to put the information into a grid?? ----------------
Joe
 
set a program stop at the While Not and see if it's going through the loop, if it isn't then try:

DoWhile percent <> count




and instead of Wend put Loop ----------------
Joe
 
A grid sounds like exactly what I am wanting. Joe, where do I locate the variable statements?
 
First see if it's going through the loop or not then we'll worr about everything else.
----------------
Joe
 
Joe, It's not going through the loop - I added the DoWhile and Loop, but to no avail. Thoughts?
 
let me create a small program and i'll play around with this and see what happens. ----------------
Joe
 
when you stop at runtime put your cursor on count and percent and see what their values are. ----------------
Joe
 
Joe,

I'm obviously in this over my head- I am not at the point in my VB training that I know how in the heck to accomplish the debug process/run to cursor/etc. Could you possibly provide a bit more detail?
 
okay when you have your program stopped, just take your mouse cursor and position it litereally on top of the variable and it will tell you the value, or in your imediate window put:
? variable name
----------------
Joe
 
When I place the cursor over Percent and/or Count, nothing happens. Is this the correct place?

count = 0
Percent = (Text1.Text / 100)
EmplName = Combo1.Text

As for the Imm. Window, typing ? Count and/or ? Percent returns nothing. Am I all wet on this?
 
put the cursor over the variables in the loop expresion.
Do While count <> percent ----------------
Joe
 
Joe, Cursor over Percent and Count yields nothing. Should it return a pop-up box with a value? Typing ? Percent (ENTER) and ? Counter (ENTER) in the Immed. Window yields nothing either.
 
you have the program stop right?? your not just stopping the program?? ----------------
Joe
 
I haven't started the program, I'm in the code window in design view -
 
you have to set a program stop in your code window on the left hand side click next to the line of code you want to stop on and it should highlight it read and put a red dot on the side, then run your program and it will stop before it executes that line of code. Then will it's running it will giv you the current value of the variables. ----------------
Joe
 
Thanks Joe for my first debugging lesson! I did as you say, and both percent and count came back = 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top