corsasport.co.uk
 

Corsa Sport » Message Board » General Chat » Any VB Programmers?


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Any VB Programmers?
Super_si
Member

Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
24th May 04 at 17:28   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 17:50   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 17:55   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:09   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:12   View User's Profile U2U Member Reply With Quote

ha

Fucking works with Combo1.newindex.

how fucking gay, cheers. Not to program the rest
Dom
Member

Registered: 13th Sep 03
User status: Offline
24th May 04 at 18:15   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:15   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:16   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:33   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:35   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 18:42   View User's Profile U2U Member Reply With Quote

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
24th May 04 at 19:03   View User's Profile U2U Member Reply With Quote

nae luck cant get text box to show the index
Super_si
Member

Registered: 4th Mar 01
Location: lurkin' somewhere........................
User status: Offline
24th May 04 at 20:07   View User's Profile U2U Member Reply With Quote

2 hours later

Text1.Text = Combo1.ItemData(Combo1.ListIndex)


 
New Topic

New Poll

Corsa Sport » Message Board » General Chat » Any VB Programmers? 24 database queries in 0.0248251 seconds