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 / June 2005

Tip: Looking for answers? Try searching our database.

OpenDatabase/OpenConnection commands

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
D Huber - 30 Jun 2005 20:26 GMT
I am trying to rewrite a database from an older version of Access to Access
2000. VBA is still fairly new to me and there is a single line of code that
is giving me a problem.

Set accrual = DBEngine.Workspaces(0).OpenDatabase("p:gautam\tables.mdb")

According to the book I have in the newer version of access, this line
should read:

Set accrual = DBEngine.Workspaces(0).OpenConnection("p:gautam\tables.mdb")

Neither of these lines work. Any help or suggestions?
Dirk Goldgar - 30 Jun 2005 20:34 GMT
> I am trying to rewrite a database from an older version of Access to
> Access 2000. VBA is still fairly new to me and there is a single line
[quoted text clipped - 10 lines]
>
> Neither of these lines work. Any help or suggestions?

OpenConnection would only be for an ODBCDirect workspace, to open a
connection to an ODBC database.  You wouldn't use it to open an .mdb
file.

What are you actually trying to do, and what error are you getting?  "It
doesn't work" isn't enough information to go on.  Is
"p:gautam\tables.mdb" a separate database from the current database?
Did you declare "accrual" As DAO.Database?

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

D Huber - 30 Jun 2005 20:43 GMT
The error message states: "Operation is not supported for this type of object."
"p:gautam\tables.mdb" is a separate database that I believe I am trying to
set accruals to, and yes accruals is declared as DAO.Database.

> > I am trying to rewrite a database from an older version of Access to
> > Access 2000. VBA is still fairly new to me and there is a single line
[quoted text clipped - 19 lines]
> "p:gautam\tables.mdb" a separate database from the current database?
> Did you declare "accrual" As DAO.Database?
Dirk Goldgar - 30 Jun 2005 20:52 GMT
> The error message states: "Operation is not supported for this type
> of object." "p:gautam\tables.mdb" is a separate database that I
> believe I am trying to
> set accruals to, and yes accruals is declared as DAO.Database.

Please post the complete code.  The following works fine for me:

   Dim accrual As DAO.Database

   Set accrual = DBEngine.Workspaces(0).OpenDatabase("c:\temp\db1.mdb")

   Debug.Print accrual.Name, accrual.TableDefs.Count

   accrual.Close
   Set accrual = Nothing

Is your code running in an .mdb file, or in an .adp?

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

D Huber - 30 Jun 2005 21:01 GMT
Option Compare Database
Option Explicit

Dim accrual As Database
Dim Accts As Recordset, MoveTable As Recordset

Dim MaxDateQry As Recordset

Dim DayCriteria As String, DayQuery As Command, WorkingSet As Recordset
Dim TableName As String, MoveTableName As String

Dim DayOfWeek As Integer, DayField, strPurpose As String, MoveDate As Date

Dim intCounter As Integer

'Movement Build variables
Dim Criteria As String, CriteriaCount As Integer

'AddMultiDay variables
Dim strMsg As String, dteCounter As Date, ctlText As Control

Public Function SelectMove()

DayOfWeek = 1
MoveTableName = "Movements"
TableName = "Accounts"
MoveDate = dteCounter
DayOfWeek = WeekDay(MoveDate, 1)

Select Case DayOfWeek
  Case 2
      DayField = "rMonday"
  Case 3
      DayField = "rTuesday"
  Case 4
      DayField = "rWednesday"
  Case 5
      DayField = "rThursday"
  Case 6
      DayField = "rFriday"
End Select

Select Case Forms![Movement Build]!cmbPurpose
   Case 99
       strPurpose = ""
   Case Else
       strPurpose = " AND [PurposeType] = " & Str$(Forms![Movement
Build]!cmbPurpose)
End Select

DayCriteria = "SELECT * FROM " & TableName & " WHERE " & DayField & " = YES"
& strPurpose

Set WorkingSet = accrual.OpenRecordset(DayCriteria)

Set MoveTable = accrual.OpenRecordset(MoveTableName)

If Not (WorkingSet.EOF) Then
   WorkingSet.MoveFirst
   Do Until WorkingSet.EOF
       For intCounter = 1 To WorkingSet!DailyOccur
           AddMovement
       Next intCounter
       WorkingSet.MoveNext
   Loop
   
   WorkingSet.Close
   MoveTable.Close
End If

End Function

Public Function Refresh_Movement_Build()
   Forms![Movement Build].Requery
   Forms![Movement Build].Refresh
End Function

Public Function GetMaxDate()
   Dim LastDate As Date, NextDate As Date, LastDay As Integer
   Dim ARTally As Database, MaxDateQry As Recordset
   
'Set accrual = DBEngine.Workspaces(0).OpenDatabase("h:\freight finance
tables.mdb")
Set accrual = DBEngine.Workspaces(0).OpenDatabase("c:\tl accrual\freight
finance tables.mdb")
Set MaxDateQry = accrual.OpenRecordset("MaxDate")

   LastDate = MaxDateQry!MaxDate
   LastDay = WeekDay(LastDate, 1)
   
   Select Case LastDay
       Case 5
           NextDate = LastDate + 3
       Case Else
           NextDate = LastDate + 1
   End Select
   
MaxDateQry.Close

End Function

Public Function AddMovement()
' this function add movements to the table
With WorkingSet
   MoveTable.AddNew
   MoveTable![AcctCodeKey] = ![AcctCodeKey]
   MoveTable![CarrierNmb] = ![CarrierNmb]
   MoveTable![Cost] = ![Cost]
   MoveTable![MiscCharge] = ![MiscCharge]
   MoveTable![FuelCharge] = ![FuelCharge]
   MoveTable![MoveDate] = MoveDate
   MoveTable![Describe] = ![Dest]
   MoveTable.Update
End With

End Function

Public Function AddMultiDay()
' this routine adds multiple days to the movement table

If IsNull(Forms![Movement Build]![StartDate]) Then
   strMsg = "Start Date can not be Null !!! Re- Enter"
   MsgBox strMsg
   Set ctlText = Forms![Movement Build]![StartDate]
   ctlText.SetFocus
   Exit Function
End If

If IsNull(Forms![Movement Build]![EndDate]) Then
   Forms![Movement Build]![EndDate] = Forms![Movement Build]![StartDate]
   Set ctlText = Forms![Movement Build]![StartDate]
   ctlText.SetFocus
   Exit Function
End If

If Forms![Movement Build]![StartDate] > Forms![Movement Build]![EndDate] Then
   strMsg = "Start Date can not be Greater than the End Date!! Check your
Dates"
   MsgBox strMsg
   Set ctlText = Forms![Movement Build]![StartDate]
   ctlText.SetFocus
   Exit Function
End If

'Set accrual = DBEngine.Workspaces(0).OpenDatabase("h:\freight finance
tables.mdb")
Set accrual = DBEngine.Workspaces(0).OpenDatabase("p:gautam\tables.mdb")

MoveTableName = "Movements"
TableName = "Accounts"

For dteCounter = Forms![Movement Build]![StartDate] To Forms![Movement
Build]![EndDate]
DayOfWeek = WeekDay(dteCounter, 1)

If DayOfWeek > 1 And DayOfWeek < 7 Then
   SelectMove
End If

Next dteCounter

strMsg = "Movements Added !!!"
MsgBox strMsg

End Function

> > The error message states: "Operation is not supported for this type
> > of object." "p:gautam\tables.mdb" is a separate database that I
[quoted text clipped - 13 lines]
>
> Is your code running in an .mdb file, or in an .adp?
Dirk Goldgar - 30 Jun 2005 21:20 GMT
> Option Compare Database
> Option Explicit
[quoted text clipped - 171 lines]
>>
>> Please post the complete code.  The following works fine for me:

Okay, so which statement is raising the error?

Note that accruals is *not* actually declared as DAO.Database, but just
as Database.  Almost certainly that means it is actually a DAO.Database,
but you could have a problem if some other library you had referenced
also defined a Database object.

For example, did you remove the default reference to ADO (ActiveX Data
Objects 2.x Library)?  If not, then it's quite likely that the recordset
objects declared in these lines:

> Dim Accts As Recordset, MoveTable As Recordset
>
> Dim MaxDateQry As Recordset
>
> Dim DayCriteria As String, DayQuery As Command, WorkingSet As
> Recordset

are all really being declared as ADODB recordsets.  Change those
declarations (and any I've missed) to be like this:

   Dim Accts As DAO.Recordset, MoveTable As DAO.Recordset

   Dim MaxDateQry As DAO.Recordset

   Dim DayCriteria As String, WorkingSet As DAO.Recordset

I don't know what you're planning to do with

   ... DayQuery As Command ...

but unless you're planning to use ADO -- and I don't see at this point
why you would -- you should probably drop that declaration altogether
and use DAO objects to do whatever you need to do.

I'm concerned that you might end up opening the external database twice
(as far as I can tell from this code), and I don't see code to close
that database.  Those might be issues you should address, but I don't
think they're relevant to your immediate problem.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

D Huber - 30 Jun 2005 21:06 GMT
mdb

> > The error message states: "Operation is not supported for this type
> > of object." "p:gautam\tables.mdb" is a separate database that I
[quoted text clipped - 13 lines]
>
> Is your code running in an .mdb file, or in an .adp?
 
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.