Need help Trying to access field, in a table, in a Acces 2003 mdb -- Newbie to DotNet -
08-13-2006
, 06:38 PM
Hello all.
I'm converting from VB6 to vb.net 2003.
And I'm also doing my second .mdb project. This time however, it's a larger
mdb file with multiple tables and fields.
What I am trying to do is open the database, search a field within
a table called "MasterItemSummary" for a match to the inputstr$,
and then set the currentrecord of the working table to the record located.
If there is more than 1 record that matches the searchstr$, I want to
put the records into a list box, and have it selectable by the user.
Once the click event is detected in the listbox, I want the currentrecord
to be set to the item the user picked. The table being used that will
display the data is called "Masterdetails"
I am using vb6 enterprise. Below is the structure of the database.
Database - XPPracticeDSN
- There are 4 tables in this field
Accounting
MasterItemSummary
Masterdetails
Electronics
- There are multiple fields in each table. (From 6 to 35 fields).
Note: The working table is being manipulated using the form and controls. The searches
are being handled by codding after a button press. The search will eventually need to be
able to search a field, inside a table, using multiple fields as the criteria.
=================== search code so far... which does not work.. =============
Private Sub cmdLast6_Click()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim searchstr$
Dim rstSQLString$
Dim FoundItem As Integer
Dim founditems()
Dim NumRecords As Long
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.Open "XPPracticeDSN" 'Database name, added as an ODBC datasource, system tab
'below is the name of the specific table I need access to
rst.Open "MasterItemSummary", con, adOpenDynamic, adLockOptimistic, adCmdTable
prompt$ = "Enter the Last Six (6) digits of the S/N for the item."
searchstr$ = InputBox(prompt$, "Last 6 Of S/N")
searchstr$ = "Last6Num = " & searchstr$ ' Last6Num is the specific field I need to search
NumRecords = rst.RecordCount
rst.MoveFirst
'There are 4 practice records fully entered in table being accessed. They are seen from
'the ado.datacontrol on the form just fine.
MsgBox "Number of records in database are: " & NumRecords
If NumRecords < 1 Then ' at this point, NumRecords is equal to -1
Exit Sub
End If
ReDim founditems(NumRecords)
FoundItem = 0
If (SupportsTransactions(con)) Then con.BeginTrans
'rst.MoveFirst
'rst.Find searchstr$
' manipulate the data here <<< What I want to do here >>>
'===============================================
searchstr$ = InputBox(prompt$, "Last 6 Of S/N")
rst.MoveFirst
rst.Index = "Last6Num" 'use S/N Last 6 digits
rst.Seek "=", searchstr$ 'and search
rst.Index = "PrimaryKey" 'reset primary key
If rst.DataMember = searchstr$ Then
FoundItem = FoundItem + 1
founditems(FoundItem) = rst.Bookmark
End If
If FoundItem = 0 Then
rst.MoveFirst 'go to first record
MsgBox "Item not Found. Verify and search again!"
End If
'===============================================
If (SupportsTransactions(con)) Then con.CommitTrans
found = 0
con.Close
Set con = Nothing
End Sub
=============== end of code ================
Please guide me!
Arcadia |