Hola.
Bien mi idea es insertar unas variables en una plantilla dichas variables se
actualizaran dependiendo del usuario que abra la plantilla por supuesto a de
leer en el sql server todo esto ok.
Problemas:
Como inserto estas variables de usuario en el documento. (Usuario, Telefono,
Mail, Fax.) de momento lo he solucionado con marcadores
Private Sub Document_New()
On Error GoTo Trap
Dim Fa As Long
Dim ComputerName As String
Dim Username As String
ComputerName = String$(255, 0)
Fa = 255
GetComputerName ComputerName, Fa
ComputerName = Left(ComputerName, Fa)
Username = String$(255, 0)
Fa = 255
GetUserName Username, Fa
Username = Left(Username, Fa - 1)
If Conect.State = adStateOpen Then Conect.Close
Conect.Open ("Provider=MSDASQL.1;Password=ppppp;Persist Security
Info=False;User ID=pppp;Data Source=An;Mode=ReadWrite;Initial Catalog=An")
If RsUsuario.State = adStateOpen Then RsUsuario.Close
RsUsuario.Open "SELECT Usuarios.* FROM Usuarios WHERE Alias='" &
Username & "'", Conect, adOpenDynamic, adLockReadOnly
If RsUsuario.EOF Then
MsgBox "El Usuario: " & Username & " No tiene permisos " & vbCrLf &
vbCrLf & "Contacte con el administrador", vbOKOnly + vbInformation, "No
tiene permisos"
'Si no tiene permisos salir sin grabar
Application.ActiveDocument.Saved = True
Application.Quit
Close
Else
With ActiveDocument.Bookmarks
.Item("Usuario").Range.InsertAfter RsUsuario.Fields("Usuario")
.Item("Mail").Range.InsertAfter RsUsuario.Fields("Mail")
.Item("Fax").Range.InsertAfter RsUsuario.Fields("Fax")
.Item("Telefono").Range.InsertAfter RsUsuario.Fields("Telefono")
End With
Exit Sub
End If
Set Conect = Nothing
Set RsUsuario = Nothing
On Error GoTo 0
Exit Sub
Trap:
Select Case Err.Number
Case -2147467259
CreateDSN "An", "SQL Server", "An", "MA", "No"
Resume
Case Else
MsgBox "Error: " & Err.Number
Application.ActiveDocument.Saved = True
Application.Quit
Close
End Select
End Sub
Leer las respuestas