Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I have an Access 2003 db that has a form that has a CommonDialog control on it which works fine.

    If I load it in Access 2007 on a new machine I get a "No object in this control" error and when I go to build, the CD control box is empty.

    If I try and add a CommonDialog Class from the ActiveX Controls I get "Operation on OLE object failed. OLE server may not be registered"

    I have run the Office repair utility and also completely uninstalled Office, rebooted and reinstalled but I still get the same error. I have searched but cannot find reference to which exact file needs to be registered or where to find it

    I am running Win7 and have the following references set:

    VB for Apps
    Access 12 object library
    OLE automation
    MS DAO 3.6
    MS ActiveX 2.1
    MS Forms 2.0
    MS windows common controls 6
    MS OLE DB error library
    "Heading for the deep end"

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I'd avoid the use of the Common Dialog control.

    Access 2002 and later have the Application.FileDialog object that can be used to display a File Open, File Picker and Folder Picker dialog (but not a Save As dialog, stupidly enough).

    See the attached demo for a way to display file dialogs using only Windows API functions. To use it in your database, import the module and class module from the demo database. The form in the database demonstrates how to invoke the dialog.

    [attachment=87206:FileDialogs.zip]
    Attached Files Attached Files

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Umm, thanks Hans but the coding is a bit beyond me. Could you write the code for a button to open a file picker window to select a file to be opened and read by the code?

    This what I need to emulate:

    Code:
    CommonDialog1.ShowOpen
    
    lblDetails.Caption = "Counting Records"
    
    Me!ProgressBar2.Max = 1
    
    Open CommonDialog1.FileName For Input As #1
    Thanks in advance.
    "Heading for the deep end"

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The code could look like this:

    Code:
    Private Sub cmdOK_Click()
      Dim dlg As New CommonDialog
      Dim strFile As String
      With dlg
        ' Specify initial path
        .InitDir = Environ("UserProfile")
        ' Specify file type to display
        .Filter = "Text files (*.txt)|*.txt"
        ' Show the dialog
        If .OpenDialog = False Then
          ' User canceled the dialog
          MsgBox "No filename specified", vbInformation
          Exit Sub
        End If
        ' Get the path and filename
        strFile = .FileName
      End With
      Set dlg = Nothing
      ' Open text file
      Open strFile For Input As #1
      ' The rest of your code goes here
      ' ...
      Close #1
    End Sub

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks Hans, it works fine
    "Heading for the deep end"

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Change the line

    Code:
    .InitDir = Environ("UserProfile")
    to

    Code:
    .InitDir = "C:\MyFolder\MySubFolder"
    substituting the appropriate drive and path. If you're on a network, you can also specify a UNC path:

    Code:
    .InitDir = "\\MyServer\MyShare\MyFolder\MySubfolder"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •