Link to home
Start Free TrialLog in
Avatar of johnmadigan
johnmadiganFlag for United States of America

asked on

access open another db & form on last record

I have a button on my switchboard that opens  a second database.  I would like the second database to open on a paticular form & the last record of the form.  Here is the query for opening the second db:

Private Sub Command54_Click()
Dim strDB As String, appAccess As Access.Application
    strPath = "\\Fileserver\is_data\Documentation\IT-Private\Scheduling DB\WIP\3-25-10 WIP\"
    strDB = strPath & "Schedulingdb_ShipSplitBatch.accdb"
    ' Create new instance of Microsoft Access.
    Set appAccess = CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strDB
    appAccess.Visible = True
    appAccess.UserControl = True '
End Sub

Any suggestions?
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Private Sub Command54_Click()
Dim strDB As String, appAccess As Access.Application
    strPath = "\\Fileserver\is_data\Documentation\IT-Private\Scheduling DB\WIP\3-25-10 WIP\"
    strDB = strPath & "Schedulingdb_ShipSplitBatch.accdb"
    ' Create new instance of Microsoft Access.
    Set appAccess = CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strDB
    appAccess.Visible = True
    appAccess.UserControl = True '

   appAccess.docmd.openform "formX" ' add this line  
End Sub
if your table on which the form is based has a field, e.g. named "date", with the date of creation for a record you can add this to reverse the order (get the last record)

appAccess.Forms.Item("FormX").OrderBy("date DESC")

the same can be done with an autonumber field, e.g named "ID"

appAccess.Forms.Item("FormX").OrderBy("ID DESC")
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ah yeah my bad, that would be easier.