Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
Got a problem if anyones good at it?
Cheers, Problems to do with Indexing a Primary key
Si
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
you working with access DB's mate? i take it your doing it through the JET (or other) driver? or you using OLE?
eitherway mate, im so so on VB, but if your doing access DB's, then i only know abit on that (like read, write, recordcounts ...writing binary to MDB and abck again etc)....but yea, wack your problem up mate and ill help. Although, if your pissing around with primary keys, try doing it the OLE way, will be alot easier mate...and have a butch on www.pscode.com
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
Private Sub Form_Load()
Dim dbConnection As New Connection
Dim rsMachine As Recordset
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\ProjectV1.0.mdb;"
dbConnection.Open strConn
Set rsMachine = New ADODB.Recordset
rsMachine.Open "Machine", strConn, adOpenKeyset, adLockOptimistic, adCmdTableDir
While rsMachine.EOF = False
Combo1.AddItem rsMachine!mcNo
Combo1.ItemData(.NewIndex) = rsMachine!machinePK
rsMachine.MoveNext
Wend
Combo1.Refresh
End Sub
Problems with the .NewIndex Says Invalid or unqualifed reference.
What ive thought is i need the machine PK. So when i see the machine in the cbo, im putting the PK in a hidden text box. Simply write the PK in that box to where i need it.
But the index wont fucking work
Si
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
it should work to be honest, just have a look at it...but without going through it all etc i cant tell whats the fook up 
Although i recommend that you do everything longhand (ie: replace combo1.itemdata(combo1.newindex) = etc) just to make sure VB has fooked up somewhere and its causing the problem....
but like i said it looks like its ok 
have a butchers on pscode.com and if theres any code offering PKs etc..maybe something has got overseen
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
ha
Fucking works with Combo1.newindex.
how fucking gay, cheers. Not to program the rest
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
quote: Originally posted by Super_si
ha
Fucking works with Combo1.newindex.
how fucking gay, cheers. Not to program the rest
i thought it would be something like that, VB is usually shite for stuff like that 
but atleast you got it working mate
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
Might well have, but now the combo1 click doesnt work!!
Private Sub Combo1_Click()
rsMachine!machinePK = Combo1.ItemData(Combo1.ListIndex)
End Sub
Ideas
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
Dim dbConnection As New Connection
Dim rsMachine As Recordset //General Declatations
Dim strConn As String
Private Sub Combo1_Click()
rsMachine!machinePK = Combo1.ItemData(Combo1.ListIndex)
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\ProjectV1.0.mdb;"
dbConnection.Open strConn
Set rsMachine = New ADODB.Recordset
rsMachine.Open "Machine", strConn, adOpenKeyset, adLockOptimistic, adCmdTableDir
While rsMachine.EOF = False
Combo1.AddItem rsMachine!mcNo
Combo1.ItemData(Combo1.NewIndex) = rsMachine!machinePK
rsMachine.MoveNext
Wend
Combo1.Refresh
End Sub
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
one thing to note mate, make sure your closing all of the open connections to the DB, before you close the program (even when designing) as this can cause problems when opening it up the DB again etc
However, what does rsMachine!machinePK do? rsMachine being the recordset to the machine, but machinePK (machine primary key im guessing) isnt a standard ADODB command...either that or i have missed something unless you doing it all under .net?
but wacking the code in VB6, and im pulling up errors on the declares at the start of the code, should be Public and not Dim ...and take out the New in the dbconnection....then it works (up to not finding the db).
but yea, i still cant get my head around the !machinePK....never seen that before in the last 3 years of doing VB programming so im confussed already mate
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
rsMachine is the recordset, ! means recordset '!' joins to the attribute. being the mcNo in the datebase table learn at uni ! never practical in the real world lol
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
i thought it was something alone those line never really knew that or used that though lol 
but im lost with out running the code etc....like i said have a butchers on pscode.com mate, might be some help...but i cant see why it shouldnt work
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
nae luck cant get text box to show the index
|
Super_si
Member
Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
|
2 hours later
Text1.Text = Combo1.ItemData(Combo1.ListIndex)
 
|