Ver Mensaje Individual
  #4 (permalink)  
Antiguo 08/04/2011, 09:31
pumi
 
Fecha de Ingreso: marzo-2007
Mensajes: 127
Antigüedad: 17 años, 1 mes
Puntos: 2
Respuesta: Problema al concatenar una cadena en access

Bueno bueno, yo sigo con lo mío y voy consiguiendo cositas. Explico un poco mejor lo que quiero hacer:

Quiero poner un botón en un formulario que busque en una tabla un determinado registro en el que un determinado campo es un vínculo a un archivo (puede ser de word, excell, txt o lo que sea). Si el registro existe, al hacer clic en el botón se debe de abrir el archivo del vínculo, y si no exite, se abre el cuadro de diálogo para que se seleccione el archivo y añadir un registro a la tabla con un vínculo al archivo seleccionado en el campo correspondiente.
La segunda parte está conseguida, pero la primera no se cómo hacerla, es decir, que se abra automáticamente el fichero que viene en el campo que tiene el vínculo.

Les dejo el código que he obtenido (y adaptado un poco) de la ayuda de access.

IMPORTANTE: para que funcione todo lo referente al FileDialog se debe activar en Herramientas / referencias del Visual Basic la opción "Microsoft office 12.0 object library" (en access 2007), lo que me lleva a hacer otra pregunta: ¿se debe activar esta opción en todos los access de todos los equipos donde se vaya a usar la base de datos?.

Gracias de nuevo y espero sus respuestas a las dos preguntitas que he hecho.

-------------------------------------------------------------------------
Dim fd As Variant
Dim dbsMiBaseDatos As DAO.Database
Dim rstMiReg As DAO.Recordset
Dim MiSelect As Variant
Dim mypath As String

'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant


Set dbsMiBaseDatos = CurrentDb 'Asignamos la base de datos actual a la variable dbsMiBaseDAtos

MiSelect = "SELECT * FROM Documentos WHERE Documentos.Id=1"

Set rstMiReg = dbsMiBaseDatos.OpenRecordset(MiSelect, dbOpenDynaset)

If Not rstMiReg.EOF Then
MsgBox "hola" 'AQUI QUIERO LAS INSTRUCCIONES PARA ABRIR EL FICHERO DEL CAMPO CON EL VINCULO
Else
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd 'Use a With...End With block to reference the FileDialog object.
.AllowMultiSelect = False

'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the button.
If .Show = -1 Then

'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems

'vrtSelectedItem is aString that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
'MsgBox "The path is: " & vrtSelectedItem
MiSelect = "INSERT INTO Documentos VALUES (1,'" & vrtSelectedItem
MiSelect = MiSelect & "')"
DoCmd.RunSQL MiSelect

Next vrtSelectedItem
'The user pressed Cancel.
Else
MsgBox "Accion cancelada", , "cancelado"
End If
End With

End If

Set rstMiReg = Nothing

dbsMiBaseDatos.Close
Set dbsMiBaseDatos = Nothing

'Set the object variable to Nothing.
Set fd = Nothing

-------------------------------------------------------------------------