|
-
Jun 20th, 2000, 03:56 PM
#1
Thread Starter
Hyperactive Member
I have this scenario: I read a access database, then loop like this:
Do
txtID = "" & rs!ID
txtCustomer = "" & rs!Customer
txtCustomerID = "" & rs!CustomerID
txtPostCodes = "" & rs!POSTCODES
txtIGN = "" & rs!IGN
txtOwnMasterDatabase = "" & rs!OwnMasterDatabase
txtWebDBType = "" & rs!WebDBType
txtDongle = "" & rs!Dongle
txtCarriers = "" & rs!Carrier
txtTriQuad = "" & rs!TriQuad
txtumNumberUsers = "" & rs!umNumberUsers
txtumPassword = "" & rs!umPassword
txtumDistance = "" & rs!umDistance
txtumTariff = "" & rs!umTariff
txtumCosts = "" & rs!umCosts
txtumMultipleLogin = "" & rs!umMultipleLogin
txtISPreProccessorType = "" & rs!SetPreProccessor
rs.MoveNext
Loop Until rs.EOF
I then have check boxes 12 for instance to represent each customer, what i would like to do is loop until a check represents the txtCustomerID... any help please???
Many thanks
-
Jun 20th, 2000, 04:14 PM
#2
Fanatic Member
I'm not really sure what you are trying to do, but.
Are you saying that when a user clicks 1 of 12 checkboxes you want to find and display the coresponding customer?
If the customers ID is 1-12 then that is easy, you could use a control array.
Other wise look into using the "Tag" property of the check box. You could store each customers ID in the Tag of an individual checkbox.
Iain, thats with an i by the way!
-
Jun 20th, 2000, 04:40 PM
#3
Thread Starter
Hyperactive Member
check boxes
Easy to you perhaps, but when you've been working with VB for 5 minutes a week, not so... could you elaborate please..
Many thanks.
-
Jun 20th, 2000, 05:11 PM
#4
Fanatic Member
If the customers ID's are 1 - 12 Then :
create a checkbox on your form. Copy it and paste it to the form. this will create a control array. Repeat until you have 12 check boxes.
These will be numbered 0 - 11.
Now when the user clicks on the checkbox, you use the click event to find the customer
Code:
Private Sub Check1_Click(Index As Integer)
findCust (index)
End Sub
private sub findCust (iCust as Integer)
rs.movefirst
do until (iCust = rs!CustomerID) or (rs.eof)
rs.movenext
loop
'now display the data
End Sub
If the customers ID is going to be like "AB12Z" or something then :
When you load the form you will have to get all of the customers ID's out of the record set and place them in the Tag property of the checkboxs.
Code:
private sub getCustId()
i = 0
do until rs.eof = true
check1(i).Tag = rs!CustomerID
i = i + 1
rs.movenext
until
End Sub
Private Sub Check1_Click(Index As Integer)
findCust (check1(index).Tag)
End Sub
private sub findCust (iCust as String)
rs.movefirst
do until (iCust = rs!CustomerID) or (rs.eof)
rs.movenext
loop
'now display the data
End Sub
Iain, thats with an i by the way!
-
Jun 20th, 2000, 05:49 PM
#5
Thread Starter
Hyperactive Member
check boxes
I shall try this..
Many thanks
-
Jun 20th, 2000, 05:50 PM
#6
Thread Starter
Hyperactive Member
check boxes
Yes, txtCustomerID returns a string..
ok!
-
Jun 20th, 2000, 06:55 PM
#7
Thread Starter
Hyperactive Member
check boxes
private sub getCustId()
i = 0
do until rs.eof = true
check1(i).Tag = rs!CustomerID
i = i + 1
rs.movenext
until ' Shouldn't this be 'Loop'
End Sub
-
Jun 20th, 2000, 07:19 PM
#8
Fanatic Member
alright, don't get arsy with me.
When i am writing code of the top of my head like that i often revert back to my days of pascal, as that is the first language i learnt.
Sorry.
Iain, thats with an i by the way!
-
Jun 20th, 2000, 07:31 PM
#9
Thread Starter
Hyperactive Member
check boxes
What if i had multiple selections
-
Jun 20th, 2000, 07:41 PM
#10
Fanatic Member
Explain?
What do you mean by multiple selections, and what would you like to do with them?
Iain, thats with an i by the way!
-
Jun 20th, 2000, 07:43 PM
#11
Thread Starter
Hyperactive Member
check boxes
What part of the world are you from.. i've never heard of that saying before.. anyhow sorry for being arsy?? yeh, sounds great.
Cheers
-
Jun 20th, 2000, 07:46 PM
#12
Thread Starter
Hyperactive Member
check boxes
This works.. thanks for that.. last question, what if i selected multiple check boxes?
-
Jun 20th, 2000, 08:02 PM
#13
Fanatic Member
Oh yeah i forgot some info. You probably already know any way.
When the check box is clicked on you will have to check the value to see if it is checked or not. If it is checked then display customer, if it is unchecked then clear info.
If you clicked a second box, it would just show the most recently clciked check boxes customer.
if you only want one box at a time checked i suggest using radio buttons.
Just to answer your other question, i'm in England. i think it might be spelled arsey actually. Not really sure.
Iain, thats with an i by the way!
-
Jun 20th, 2000, 08:12 PM
#14
Thread Starter
Hyperactive Member
check boxes
Yep, me again, so if i did have ticked say, 4 check boxes, this method is useless?
Regards
ps: What if i wanted a select all box as well.?
-
Jun 20th, 2000, 08:50 PM
#15
Fanatic Member
How do you intend to display multiple customers at the same time. Please explain what you want to achieve
Iain, thats with an i by the way!
-
Jun 20th, 2000, 10:06 PM
#16
Thread Starter
Hyperactive Member
check boxes
On first selected check box, create an app for that customer, on the other check box selection do the same and so on..
Many thanks
-
Jun 20th, 2000, 10:15 PM
#17
Fanatic Member
I can't see a problem with that. By app, do you mean shell a new application, or a new form?
You could create any number of instances of a customer detail form.
Iain, thats with an i by the way!
-
Jun 20th, 2000, 10:39 PM
#18
Thread Starter
Hyperactive Member
check boxes
No, an application is built per customer so the scenario is
check1(3) say smith
build application
repeat until none selected
Hope this helps
-
Jun 20th, 2000, 10:52 PM
#19
Fanatic Member
i'm begining to get the picture now. Let me see if i have got it right.
You have (lets say) 12 checkboxes.
The user can click any number of these.
When they have done selecting, then you want to hit a command button (GO) that will start the app building.
Right? If not the following will be a load of useless crap.
When they hit the GO button you you loop thorugh all of the 12 check boxes and check the value. If the box is checked then you call the find cust, then you build yuor app, or whatever.
Code:
Private Sub cmdGO_Click()
Dim i As Integer
For i = 0 To 11
If check(i).value = vbChecked Then
If findCust(check(i).tag) = True Then
'build app or whatever
Else
Msgbox "The Customer was not found!"
End If
End If
Next i
End Sub
Private Function findCust (iCust as String) As Boolean
rs.movefirst
Do Until (findCust = True) or (rs.EOF)
If iCust = rs.CustomerID Then
findCust = True
End If
rs.MoveNext
Loop
End Sub
Iain, thats with an i by the way!
-
Jun 20th, 2000, 11:02 PM
#20
Thread Starter
Hyperactive Member
check boxes
Thanks for that, i'll try it!!
-
Jun 20th, 2000, 11:34 PM
#21
Thread Starter
Hyperactive Member
check boxes
Can the for loop not be as restricted ie: be the length of how many check boxes their are?
Regards
-
Jun 21st, 2000, 12:05 AM
#22
Fanatic Member
Of course it can.
Code:
For i = Check1.LBound To Check1.UBound
'blah blah blah
Next i
Iain, thats with an i by the way!
-
Jun 25th, 2000, 03:52 PM
#23
Thread Starter
Hyperactive Member
check boxes
Where was we up to... ahhh! is this an initialisation.?
-
Jun 25th, 2000, 04:07 PM
#24
Fanatic Member
Hello again.
Pardon? What do you mean?
Iain, thats with an i by the way!
-
Jun 25th, 2000, 04:15 PM
#25
Thread Starter
Hyperactive Member
check boxes
After a weekend of booze, i can understand that reply
For i = Check1.LBound To Check1.UBound
'blah blah blah
Next i
Is this an initialisation process?
-
Jun 25th, 2000, 04:21 PM
#26
Fanatic Member
You asked if the for loop can be for the number of checkboxes there are.
check1.lbound gives you the lowest number in the control array (0 or 1 probably)
check1.ubound gives you the highest number in the control array (if you have 12 boxes, then 11 if you start at 0 or 12 if you start at 1)
So the loop will go through each checkbox you have, without hardcoding a number. This will allow you to change the number of checkboxes, without changing the loop code.
Code:
Private Sub cmdGO_Click()
Dim i As Integer
For i = Check1.LBound To Check1.Ubound
If check(i).value = vbChecked Then
If findCust(check(i).tag) = True Then
'build app or whatever
Else
Msgbox "The Customer was not found!"
End If
End If
Next i
End Sub
Private Function findCust (iCust as String) As Boolean
rs.movefirst
Do Until (findCust = True) or (rs.EOF)
If iCust = rs.CustomerID Then
findCust = True
End If
rs.MoveNext
Loop
End Sub
Iain, thats with an i by the way!
-
Jun 26th, 2000, 04:08 PM
#27
Thread Starter
Hyperactive Member
check boxes
Hello again,
I'm having difficulty fitting the formentioned loops to my scenario, my scenario is this
Do Until (rs.EOF)
txtID = "" & rs!ID
txtCustomer = "" & rs!Customer
txtCustomerID = "" & rs!CustomerID
txtPostCodes = "" & rs!POSTCODES
txtIGN = "" & rs!IGN
txtOwnMasterDatabase = "" & rs!OwnMasterDatabase
txtWebDBType = "" & rs!WebDBType
txtDongle = "" & rs!Dongle
txtCarriers = "" & rs!Carrier
txtTriQuad = "" & rs!TriQuad
txtumNumberUsers = "" & rs!umNumberUsers
txtumPassword = "" & rs!umPassword
txtumDistance = "" & rs!umDistance
txtumTariff = "" & rs!umTariff
txtumCosts = "" & rs!umCosts
txtumMultipleLogin = "" & rs!umMultipleLogin
txtISPreProccessorType = "" & rs!SetPreProccessor
If (iCust = rs!CustomerID) Then
'build the app
Else
End If
rs.MoveNext
Loop
How could i place the code you give me into this scenario:?
cmdGO_Click()
Dim i As Integer
For i = Check1.LBound To Check1.Ubound
If check(i).value = vbChecked Then
If findCust(check(i).tag) = True Then
'build app or whatever
Else
Msgbox "The Customer was not found!"
End If
End If
Next i
End Sub
Private Function findCust (iCust as String) As Boolean
rs.movefirst
Do Until (findCust = True) or (rs.EOF)
If iCust = rs.CustomerID Then
findCust = True
End If
rs.MoveNext
Loop
End Sub
-
Jun 26th, 2000, 04:24 PM
#28
-
Jun 26th, 2000, 04:38 PM
#29
Thread Starter
Hyperactive Member
check boxes
-
Jun 26th, 2000, 05:26 PM
#30
Thread Starter
Hyperactive Member
check boxes
Everything going great but arrrrggghhhh!! again, how do i disable the automatic run when i tick a check box?
-
Jun 26th, 2000, 05:29 PM
#31
Fanatic Member
Right.
Code:
Private Sub Form_Load()
getCustId
End Sub
Private Sub getCustId()
Dim i As Integer
i = 0
rs.movefirst
do until rs.eof = true
check1(i).Tag = rs!CustomerID
i = i + 1
rs.movenext
until
End Sub
Private Sub cmdGO_Click()
Dim i As Integer
For i = Check1.LBound To Check1.Ubound
If check(i).value = vbChecked Then
If findCust(check(i).tag) = True Then
displayCust
'build app or whatever
Else
Msgbox "The Customer was not found!"
End If
End If
Next i
End Sub
Private Function findCust (iCust As String) As Boolean
rs.movefirst
Do Until (findCust = True) Or (rs.EOF)
If iCust = rs.CustomerID Then
findCust = True
Exit Function
End If
rs.MoveNext
Loop
End Sub
Private Sub DisplayCust()
txtID = "" & rs!ID
txtCustomer = "" & rs!Customer
txtCustomerID = "" & rs!CustomerID
txtPostCodes = "" & rs!POSTCODES
txtIGN = "" & rs!IGN
txtOwnMasterDatabase = "" & rs!OwnMasterDatabase
txtWebDBType = "" & rs!WebDBType
txtDongle = "" & rs!Dongle
txtCarriers = "" & rs!Carrier
txtTriQuad = "" & rs!TriQuad
txtumNumberUsers = "" & rs!umNumberUsers
txtumPassword = "" & rs!umPassword
txtumDistance = "" & rs!umDistance
txtumTariff = "" & rs!umTariff
txtumCosts = "" & rs!umCosts
txtumMultipleLogin = "" & rs!umMultipleLogin
txtISPreProccessorType = "" & rs!SetPreProccessor
End Sub
Iain, thats with an i by the way!
-
Jun 26th, 2000, 07:38 PM
#32
Thread Starter
Hyperactive Member
parameters
Shouldn't displayCust take a parameter?
-
Jun 26th, 2000, 07:59 PM
#33
Fanatic Member
Nope. We have already moved to the right posiiton in the recordset, so we just tell the procedure to display whatever is at that current position.
Iain, thats with an i by the way!
-
Jun 26th, 2000, 08:05 PM
#34
Thread Starter
Hyperactive Member
GLOBALS
So these variables will have to be global..?
"i dont like global variables..!!!" Thanks for your help
-
Jun 26th, 2000, 08:11 PM
#35
Fanatic Member
Like them or lump them, Global variables are a must in VB.
In the good old days of pascal, it was possible to write a program without a single Global variable. I managed to write a scheduling program for a fire station (for my A-level project) without using a single one. This encourages good coding.
Unfortunaley, the same is imposible with VB. Try it and see how far you get. (i estimate about nowhere), so get used to them.
Iain, thats with an i by the way!
-
Jun 27th, 2000, 08:45 AM
#36
-
Jun 27th, 2000, 04:42 PM
#37
Thread Starter
Hyperactive Member
LAST HURDLE
Where do i call the declarations for set database, it doesn't like this??
Option Explicit
Dim lne$
Dim DirFlag As Boolean
Dim FilesCopied As FileSystemObject
Dim DB As Database
Dim rs As Recordset
'set db location
Set DB = OpenDatabase(App.Path & "\configuration.mdb")
'Open the Contact table
Set rs = DB.OpenRecordset("SELECT netVESPAWeb.*, ISDefine.SetPreProccessor, altCarriers.Carrier FROM (ISDefine INNER JOIN netVESPAWeb ON ISDefine.ID = netVESPAWeb.ISPreProccessorType) INNER JOIN altCarriers ON netVESPAWeb.SetCarriers = altCarriers.ID", dbOpenDynaset)
-
Jun 27th, 2000, 05:23 PM
#38
Thread Starter
Hyperactive Member
select all
Is this correct for select all??
For i = Check1.LBound To Check1.Ubound
Check1(i).value = vbChecked
Next i
-
Jun 27th, 2000, 07:09 PM
#39
Fanatic Member
Answer to First post is on its way via E:mail.
Answer to second post = Exactly right.
Iain, thats with an i by the way!
-
Jun 28th, 2000, 04:09 AM
#40
Now that's a question no one aks
For me only approx 30 or so questions...however generally post questions internally on our intranet which we share with a couple of other companies. Only if caren't get answer will post to this site. But...and this is a big but...have picked up ideas/solutions/techniques from reading other posts.
Generally skim through once or twice a day to see if l can help anyone out. Didn't know about this site when l started vb, and man it would have solved some late nights and the cost of books.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|