Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2005

Tip: Looking for answers? Try searching our database.

Index

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
craignbaker@hotmail.com - 14 May 2005 05:55 GMT
I would like to use the Seek function to find the details in a table and then
write it into a new record.

Private Sub ItemID_AfterUpdate()

Dim mydb As Database
Dim myset As Recordset
Dim ItemId As Integer
Dim CurrentPrice As Currency

Set mydb = CurrentDb()

'gets the value of the technicians name being sought
ItemId = InputBox("Enter the ItemID")

With rstItems
'Set the index."
myset.Index = "ItemID"
End With

'searches the recordset for the technician name inputted above
myset.Seek "=", [ItemId]

'if there is no match (the technician name is not found) then put up a
'messagebox
If myset.NoMatch Then
       MsgBox ("ItemId not found")
Else
 
'open the form, go to the technician name field and find the record
specified 'above
[CurrentPrice] = myset!Price
Quantity.SetFocus

End If
End Sub

The problem comes up at setting the index. Any help would be appreciated.
Thankyou.
Allen Browne - 14 May 2005 06:51 GMT
Open the table in design view.
Open the Indexes box (View menu).
What is the Name of the index?
It may be different from the name of the field.
For example, the index might be named "PrimaryKey".

Please note that this code works only with local tables, not attached
tables. When you OpenRecordset() on a local table, it defaults to
dbOpenTable, whereas an attached table uses dbOpenDynaset. Since most
databases end up being split, it might be better to just open the recordset
with the record you desire:
   strSql = "SELECT Price FROM Table1 WHERE ItemId = " & ItemId & ";"
   Set myset = mydb.OpenRecordset(strSql)

Of course, for that simple example you could just use DLookup(), but that's
the idea.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I would like to use the Seek function to find the details in a table and
>then
[quoted text clipped - 36 lines]
> The problem comes up at setting the index. Any help would be appreciated.
> Thankyou.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.