Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a BeforUpdate() to .adp

Status
Not open for further replies.

ind

Programmer
Mar 9, 2000
121
US
If have a procedure that searches for duplicate records...
Private Sub_BeforeUpdate(Cancel as Integer)
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("PurchaseOrders", dbOpenTable)
rst.index = "PrimaryKey"
rst.Seek "=", Me!PurchaseOrderNumber
If Not rst.NoMatch Then
MsgBox "PO #" & Me.PurchaseOrderNumber & " has already been issued." & vbCrLf & "Please enter a unique PO #.", vbOKOnly + vbExclamation, "PO Conflict"
DoCmd.RunCommand acCmdUndo
Cancel = True
End If

I need need this to work in a access project (.adp)
Having major trouble. Any help is appreciated.
 
Well, there are a number of issues here. I suspect you have recently converted this from an Access 97 database to Access 2000 ADP. In Access 2000 rather than using DAO as the default recordset it uses ADODB. You need to prepend every DAO object with DAO in Access 2000.

Dim rst As DAO.Recordset

Then the CurrentDb points to the front end database and if you are using an Adp file then you may have to identify the location of the server database with the records and open it as a database using code.

Dim wsp As Workspace
Dim pstrSAppName As String
Dim pdbServer As Database
Dim rst As DAO.Recordset

pstrSAppName = "C:\MyDb.mdb"
Set wsp = DBEngine.Workspaces(0)
Set pdbServer = wsp.OpenDatabase(pstrSAppName)

pdbServer is now open as a database and you can open the recordset.

Set rst = pdbServer.OpenRecordset("PurchaseOrders", dbOpenTable)


Steve King Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top