Archivo

Archivo para Agosto 2007

Modifica las propiedades de un campo de una tabla

Sub sChangeField(strTableName As String, strFieldName As String, strFieldType As String)
Dim db As Database
Dim strSQL As String
Set
db = CurrentDb
‘ Agrega un nuevo campo en la tabla
‘ con un nombre temporal (TempField)
strSQL = “ALTER TABLE [" & strTableName & _
"] ADD COLUMN [TempField] ” & _
strFieldType & “;”
db.Execute strSQL
‘ Copia los datos del campo existente al nuevo
strSQL = “UPDATE DISTINCTROW [" & strTableName & _
"] SET [" & strFieldName & "]=[TempField];”
db.Execute strSQL
‘ Elimina el campo antiguo
strSQL = “ALTER TABLE [" & strTableName & _
"] DROP COLUMN [" & strFieldName & "];”
db.Execute strSQL
‘ Renombra el nuevo campo con el nombre del campo antiguo
db.TableDefs(strTableName).Fields(“TempField”).Name = strFieldName
Set db = Nothing
End Sub

Categorías:Microsoft Access

Eliminar las tablas vinculadas

Sub sRemoveLinks()
Dim db As Database
Dim tdf As TableDef
Dim intCount As Integer, intPos As Integer
Set
db=DBEngine(0)(0)
intCount=db.TableDefs.Count-1
For intPos=intCount to 0 Step -1
Set tdf=db.TableDefs(intPos)
If Len(tdf.Connect)>0 Then
DoCmd.DeleteObject acTable, tdf.Name
End If
Next
intPos
End Sub

Categorías:Microsoft Access

Comprueba la existencia de una objeto en una base de datos

Public Const fForm = “Forms”
Public Const fReport = “Reports”
Public Const fMacro = “Scripts”
Public Const fModulo = “Modules”
Public Const fTabella = “Tables”
Public Const fQuery = “Queries”

Public Function Existe_Objeto(ByVal Nome_Ogg As String, _
Typ_Ogg As String, _
Optional ByVal Nome_Dbs As String = vbNullString) As Boolean
‘*****************************************************************
‘Nombre : Existe_Objeto (Function)
‘Propósito: Verificar la existencia de una objeto en la base de datos(Table, Query, Form or …) Exist
‘Inputs : String=Object Name
‘ : Type=”Tables” or “Forms” or “Queries”
‘ : “Scripts” or “Reports” or “Modules”
‘ : Nome_Dbs=Database.mdb (Source where Function search)
‘Output : True if Object Exist
‘*****************************************************************
Dim dbs As Database
Dim tdf As TableDef
Dim qdf As QueryDef
Dim x, num_ogg As Integer
If IsMissing
(Nome_Dbs) Or Nome_Dbs = vbNullString Then
Set
dbs = CurrentDb
Else
Set
dbs = OpenDatabase(Nome_Dbs)
End If
Select Case
Typ_Ogg
Case fTabella
For Each tdf In dbs.TableDefs
If tdf.Name = Nome_Ogg Then
Existe_Objeto = True
dbs.Close
Set dbs = Nothing
Exit Function
End If
Next
tdf

Case fQuery
For Each qdf In dbs.QueryDefs
If qdf.Name = Nome_Ogg Then
Existe_Objeto = True
dbs.Close
Set dbs = Nothing
Exit Function
End If
Next
qdf

Case fForm, fModulo, fMacro, fReport
num_ogg = dbs.Containers(Typ_Ogg).Documents.Count
For x = 0 To num_ogg – 1
If dbs.Containers(Typ_Ogg).Documents(x).Name = Nome_Ogg Then
Existe_Objeto = True
dbs.Close
Set dbs = Nothing
Exit Function
End If
Next
End Select
Esci:
Existe_Objeto = False
dbs.Close
Set dbs = Nothing
End Function

Categorías:Microsoft Access

Fechas en Access (I)

Una fecha (un día concreto) en Access es un nº entero, no una combinación de números y separadores, ni de palabras ni de formatos. Hoy día 15 de Noviembre de 2003, sábado es, para Access, el día 37940 (y así se almacena). Lo pongas en el formato que quieras (un montón de posibles combinaciones), internamente es el 37940.

Ayer fue el 37939 y mañana será 37941. Y dentro de mil días será el 38940. Ahora bien, para enseñarlo o hablar de hoy no decimos el día 37940, porque sería un rollo, sino que decimos o ponemos 15 de Noviembre de de 2003, sábado, ó 15-11-03, ó 15/11/2003, ó 15/11/2003, ó 11/15/2003, ó 2003/15/11, ó 15/2003/11/, ó más de tropecientas combinaciones sin contar las versiones del calendario musulmán, ni judío, ni chino, ni japonés tradicional.

 

Todos hablamos del mismo hecho, día, pero lo expresamos de distinta forma. Así que, ¿son iguales todas ellas?. En expresión, no; pero en contenido, sí.

Leer más…

Categorías:Microsoft Access

Funciones de Visual Basic para Excel

Categorías:Microsoft Access

Funciones para Access

Categorías:Microsoft Access

Función que determina el origen de una tabla vinculada

Public Function GetDataPath(strTable As String) As String
On Error GoTo Err_Handler

‘Purpose: Return the full path of the file from the Connect property of this tabledef.
‘Return: Full path and file name for attached MDB.
‘Just the path for some other types (e.g. attached text.)
‘ Zero-length string for local table (not attached), or of argument is zero-length.
‘ “#Error” on error, e.g. table not found.
‘Requires: Split() function for Access 97 or earlier.

Dim varArray As Variant
Dim i As Integer

If Trim$(strTable) <> vbNullString Then
varArray = Split(CurrentDb.TableDefs(strTable).Connect, “;”)
For i = LBound(varArray) To UBound(varArray)
If varArray(i) Like “DATABASE=*” Then
GetDataPath = Trim$(Mid$(varArray(i), 10))
Exit For
End If
Next
End If

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & “.GetDataPath”, strTable, False)
GetDataPath = “#Error”
Resume Exit_Handler

End Function

Categorías:Microsoft Access

Uso del XML para manejar recordsets desconectados

Los Recordset desconectados se usan en aplicaciones Cliente-Servidor, tal como el Web. Entiéndase un Recordset desconectado aquel que no tiene referencias a la base de datos. Es decir, existe como un objeto que encapsula datos y su definición, y que no sabe nada de la base de datos que lo suministro. De aquí que el XML es una forma realmente eficaz de transmitir datos. Desde la versión 2.1 de ADO, podemos Salvar y Cargar conjuntos de datos en formato XML, que fueron estructurados por un Recordset fr ADO. Leer más…

Categorías:Microsoft Access

Simplificando ADO

Yo he simplificado mucho mi escritura de software de acceso a datos al hacer funciones reutilizables que encapsulan operaciones de ADO. Naturalmente estas funciones van a parar en un componente ActiveX que bautice ADOFunctions.
Leer más…

Categorías:Microsoft Access

Cuadros de diálogo

‘Ejemplos de los métodos para Seleccionar Impresora, Abrir, Guardar

 

‘Seleccionar impresora

On Local Error Resume Next

CommonDialog1.CancelError = True

CommonDialog1.Flags = cdlPDPrintSetup

CommonDialog1.ShowPrinter Err = 0

 

‘Abrir On Local Error Resume Next

CommonDialog1.CancelError = True

 

‘Especificar las extensiones a usar

CommonDialog1.DefaultExt = “*.crd”

CommonDialog1.Filter = “Cardfile (*.crd)|*.crd|Textos (*.txt)|*.txt|Todos los archivos (*.*)|*.*”

CommonDialog1.ShowOpen

If Err Then

 

‘Cancelada la operación de abrir

Else sArchivo = CommonDialog1.FileName

End If

 

‘Guardar

On Local Error Resume Next CommonDialog1.CancelError = True

 

‘Especificar las extensiones a usar

CommonDialog1.DefaultExt = “*.crd”

CommonDialog1.Filter = “Cardfile (*.crd)|*.crd|Textos (*.txt)|*.txt|Todos los archivos (*.*)|*.*”

CommonDialog1.FileName = sArchivo

CommonDialog1.ShowSave

If Err Then

 

‘Cancelada la operación de guardar

Else sArchivo = CommonDialog1.FileName

End If

Categorías:Microsoft Access