Anda di halaman 1dari 8

PGINAS DE ACCESS IMPRESCINDIBLES

Para evento de botn que combine datos de formulario con documento de word (registro activo) support.microsoft.com/kb/131583/es Ejemplos de expresiones http://www.duiops.net/manuales/access/access19.htm Sitio de un chico bastante empollado http://www.mvp-access.es/emilio/Access.asp Copiar datos de subformulario a formulario (por ejemplo, en un campo de filtro) forms.parent.txtCod.Value=me.CODIGO.value En mi caso: Private Sub Form_DblClick(Cancel As Integer) [Form_4 Formulario Informe].CAMPO_UTM.Value = Me.UTM.Value End Sub AYUDA PARA FORMULARIOS Quera modificar un campo de un registro, basndome en una lista de posibilidades (p.e. tipo de estructura, de propiedad, de proteccin, etc) DATOS Origen de control Tipo de origen de la fila Origen de la fila

1. Campo al que va a parar la informacin 2. Tabla/Consulta 3. Procedencia de la lista

1. Nombre del campo de la tabla en que se almacenar 2. Tabla/Consulta procede de una lista desplegable 3. Nombre de la tabla que contiene las distintas opciones. Si sta tabla tuviera varias columnas, hay que especificar la que se ofrece: SELECT[tabla origen].[CAMPO] FROM [tabla origen] Color corporativo del ayuntamiento: 9928244 AYUDA PARA EXPORTAR INFORME A WORD Quera generar, mediante botn, un archivo de word basado en una plantilla, que recoja la informacin del registro activo del formulario. El problema que ms me cost fue dar con la ruta correcta de los campos origen del registro para combinarlos en el documento de word. 1. Crear documento de word. 2. Se sealan palabras clave (que luego sern sustitudas) con un marcador: elige nombres lgicos, pues luego hay que referenciarlos en access. MARC 3. En el formulario se preparan los campos que exportarn los datos. Yo los he ocultado tras un subformulario (puesto que slo me sirven para transportar la informacin al documento word) y les he dado nombres especiales, del tipo CAMPOInf 4. La orden para sustituir las palabras marcadas es:

.ActiveDocument.Bookmarks(MARC).Select .Selection.Text = (CStr(Form![CAMPOInf])) ABRIR FORMULARIO CON VENTANA MAXIMIZADA DIRECTAMENTE En el evento Al cargar se introduce la siguiente orden: =[DoCmd].[Maximize] CONDICIONAL EN CONSULTA Siinm(condicin;datoSiVerdadero;datoSiFalso) CURSO ONLINE GRATIS http://www.wikilearning.com/curso_gratis/curso_de_microsoft_access_xp/4443 BOTN CON CONDICIONAL http://forums.aspfree.com/microsoft-access-help-18/text-box-used-as-a-button-change-colourof-text-box-527156.html I have a continuous form that is a subform that sits on another form. The Button sits on this subform and the onClick event for this button is this: Private Sub AllowClick_Click() If Me.AllowClick = True Then CurrentDb.Execute "UPDATE TABLE_NAME SET TABLE_NAME.FNLVARTTL = " & Nz(Me.txtLoad, 0) & " WHERE(TABLE_NAME.ID_FIELD) = " & Me.ID_FIELD_FROM_OTHER_TABLE End If End Sub What this does is when you click the button it puts a certain number from that ID to another Table in a column against a matching ID. This button also has conditional formatting... It is: FieldValue equal to True then it assigns a colour to the button. This means because it's a continous form, there is a "button" next to each record but only certain "buttons" are visible if they match the criteria. Now all I want is if this Button is clicked it should change the colour of it yet again for THAT SPECIFIC RECORD and not the others. BOTONES Y COLORES CONDICIONADOS http://www.utteraccess.com/forum/lofiversion/index.php/t1224260.html I have a form that uses a mouse move event to change the color of a label. So when you move the mouse over the label it turns red. When you move the mouse over another label on the form that label turns red and the other label goes back to the original color. Right now I am just using statements such as : Me.HighPressureSheet.FontWeight = 700

Me.HighPressureSheet.ForeColor = 255 Me.Gylon.FontWeight = 400 Me.Gylon.ForeColor = 16777215 Me.ChangeResetPassword.FontWeight = 400 Me.ChangeResetPassword.ForeColor = 16777215 to set the colors. But the form has a lot of labels and I do not want to have to do this for every label on the form. Can I create a generic loop to do the same thing. For example: Go to first label If label name is A then set label A fore color = 255 Else set label A fore color to 1677215 end if Go to next label and repeat I understand how to use loops, I just don't know the correct syntax for what I am trying to do. ANy help is appreciated. Thanks, ChrisO Jul 27 2006, 04:58 PM Gday Erik. Just one of many ways to do it: CODE Option Explicit Option Compare Text

Private Sub Form_Open(ByRef intCancel As Integer) Dim ctlControl As Control For Each ctlControl In Me With ctlControl If .ControlType = acLabel Then If .Tag = "IncludeInList" Then .OnMouseMove = "=HandleMouseMove('" & .Name & "')" End If End If End With Next ctlControl Me.Detail.OnMouseMove = "=HandleMouseMove('Detail')" HandleMouseMove "Detail" End Sub

Private Function HandleMouseMove(ByVal strControlName As String) Dim ctlControl As Control

[color="green"]' Reset Weight and ForeColor.[/color] For Each ctlControl In Me With ctlControl If .ControlType = acLabel Then If .Tag = "IncludeInList" Then .FontWeight = 400 .ForeColor = 16777215 End If End If End With Next ctlControl [color="green"]' Highlight Weight and ForeColor.[/color] If strControlName <> "Detail" Then Me(strControlName).FontWeight = 700 Me(strControlName).ForeColor = 255 End If End Function You will need to add IncludeInList to the Tag property of each control you wish to take part in the highlighting. If your happy with that we can add more code to reduce the number of calls to the mouse move handler. Hope that helps. Regards, Chris. esphelps Jul 31 2006, 09:44 AM Chris, Works like a charm and only took about 5 minutes to set up. This will save me lots of time as I go forward. Sincere Thanks, Erik ChrisO Jul 31 2006, 03:20 PM No problems Erik, glad to help. Regards, Chris. IbobNdave Feb 16 2008, 03:57 PM This is great code and works like a charm for a straight form. I am having issues on my frmIssue which is a mainform with a subform frmsubIssueList. I want to use this code to alter the labels on the mainform, from the mainform. When I put this code in it burps on assiging the .OnMouseMove option.

I have tried to figure this out using the Syntax for Subs documentation I have and I am having no luck. Help? How do I code this for the mainform frmIssue? Matthew.. ChrisO Feb 16 2008, 05:48 PM Gday Matthew. One reason it might not work correctly is that Labels which are attached to other controls do not have events. For this to work, all the Labels need to be stand alone Labelsnot attached to any other control. Regards, Chris. IbobNdave Feb 17 2008, 10:52 AM The labels I want to attach this event to are stand alone. Narnek Feb 17 2008, 12:43 PM Hello, i have had problems with sub forms because as a subform there is no detail event. the sub form is a control not a form. this code works for subforms and forms

I have this in a module basCommon Public Sub SetUp(strForm As Form) Dim ctrl As Control For Each ctrl In strForm.Controls If (ctrl.tag = "Label") Then ' Create Mouse Events ctrl.OnMouseDown = "=LabelMouseDown(" & Chr(34) & ctrl.Name & Chr(34) & ")" ctrl.OnMouseMove = "=LabelMouseMove(" & Chr(34) & ctrl.Name & Chr(34) & ")" ctrl.OnMouseUp = "=LabelMouseUp(" & Chr(34) & ctrl.Name & Chr(34) & ")" End If Next Set ctrl = Nothing End Sub

'call this from the form load event 'then these are in the form's module Private Function LabelMouseDown(strLabelName As String) On Error Resume Next With Me.Controls(strLabelName) If Not Me.Controls(strLabelName).SpecialEffect Me.Controls(strLabelName).SpecialEffect = 2 End With End Function Private Function LabelMouseMove(strLabelName As String) On Error Resume Next With Me.Controls(strLabelName) ' Set up current button as highlighted If Not Me.Controls(strLabelName).SpecialEffect Me.Controls(strLabelName).SpecialEffect = 1 If Not Me.Controls(strLabelName).ForeColor = Me.Controls(strLabelName).ForeColor = 16711680 End With End Function

Then

1 16711680

Then Then

Private Function LabelMouseUp(strLabelName As String) On Error Resume Next With Me.Controls(strLabelName) If Not Me.Controls(strLabelName).SpecialEffect = 0 Then Me.Controls(strLabelName).SpecialEffect = 0 If Not Me.Controls(strLabelName).ForeColor = 0 Then Me.Controls(strLabelName).ForeColor = 0 Me.Controls(strLabelName).OnMouseMove = vbNullString End With End Function

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim ctrl As Control Dim ctrlName As String On Error Resume Next For Each ctrl In Me.Controls If (ctrl.tag = "Label") Then ctrlName = ctrl.Name If Not ctrl.SpecialEffect = 0 Then ctrl.SpecialEffect = 0 If Not ctrl.ForeColor = 0 Then ctrl.ForeColor = 0 Me.Controls(ctrlName).OnMouseMove = "=LabelMouseMove(" & Chr(34) & ctrl.Name & Chr(34) & ")" Else End If Next

Set ctrl = Nothing End Sub

Hope it helps, it's a combination of examples i found Simon Evitar datos duplicados en el mismo campo. http://www.gratiszona.com/trucos/trucos-access/evitar-datos-duplicados-mismo-campo.htm Aunque Access diga, al introducir datos en un campo clave principal en un nuevo registro, que ya existe en el campo clave principal de otro registro, avisa del error despus de que ya se ha producido, obligando a introducir todos los campos del registro duplicado hasta el final. Sin embargo, existe un procedimiento mediante el cual Access puede avisar de la duplicidad nada ms introducir el dato. Lo primero es asegurarse de que el campo a comprobar esta indexado y es clave principal. Supongamos una base de datos de pacientes que ingresan en un hospital y el objetivo es detectar que no se repita el dato introducido en el campo NumHistoria. Abrir el formulario en vista Diseo, elegir Ver/Cdigo e incluir en el apartado General/ Declaraciones (General a la izquierda y Declaraciones a la derecha) el siguiente codigo: Dim BaseDatos as DataBase Dim Pacientes as Recordset Con ello se define que van a utilizarse dos objetos DAO o de acceso a datos: una base de datos y un recordset y asegurando que sern visibles en todos los procedimientos del formulario. En el evento Al cargar del formulario incluir estas lneas de codigo: Set BaseDatos = CurrentDB() Set Pacientes = BaseDatos.OpenRecordset('PacientesIngresados',dbOpenTable) La primera lnea asigna la base de datos actual a la variable BaseDatos, la segunda asigna a la variable Pacientes los registros existentes en la tabla Pacientes Ingresados de la base de datos BaseDatos, y la abre de tipo tabla, es decir, se va a poder leer de ella por ndice, que sera el que se indica con la siguiente instruccin que debe ir a continuacin de las dos anteriores: Pacientes.Index = 'PrimaryKey' En el evento Antes de actualizar de la variable NumHistoria incluir: Sub NumHistoria_BeforeUpdate (Cancel as integer) Pacientes.Seek '=', NumHistoria If Not Pacientes.NoMatch then

Msgbox 'Num. de historia ya existente.',48 Cancel = True Exit Sub End If End Sub La instruccin que contiene Seek (que es un mtodo que solo se puede utilizar con los Recordset abiertos con dbOpenTable), lo que hace es intentar encontrar en la tabla Pacientes alguno con el nmero de historia igual a la variable NumHistoria, y va a buscar en nmeros de historia porque al cargar el formulario ya sabe que el ndice iba a ser la clave principal, que hemos supuesto que va por Nmero de Historia. INFORME: sacar informe con campo filtrado en formulario o con campo sin filtrar (todos los registros) If Nz(CampoDelFormulario, "") = "" Then 'Nada seleccionado en el combo, lanzamos el informe tal cual DoCmd.OpenReport NombreInforme, acViewPreview Else 'Lanzamos el informe filtrado DoCmd.OpenReport NombreInforme, acViewPreview, Me.[CampoDelFormulario] & "'" End If

"CampoDelInforme='"

&

Anda mungkin juga menyukai