zelarra821
Registered User.
- Local time
- Today, 06:44
- Joined
- Jan 14, 2019
- Messages
- 846
Hello.
I tell you my problem.
I want, when clicking on the form button that you see in the image I attached, to check if the active field is the dropdown also marked in said image and obtain the value.
What is the objective of this?
I want to add a code in that button to update the pricing table, without having to go to another form. In other forms without subforms, I add a Select Case so that it only works with the active field that I want. However, in this case, I think there may be two active fields (the one on the subform and then the one on the main form), and I don't know how to approach it.
I copy the code from another form so you can see what I want to achieve, but applied to a subform.
I also attach a database so you can try it.
Thanks a lot.
I tell you my problem.
I want, when clicking on the form button that you see in the image I attached, to check if the active field is the dropdown also marked in said image and obtain the value.
What is the objective of this?
I want to add a code in that button to update the pricing table, without having to go to another form. In other forms without subforms, I add a Select Case so that it only works with the active field that I want. However, in this case, I think there may be two active fields (the one on the subform and then the one on the main form), and I don't know how to approach it.
I copy the code from another form so you can see what I want to achieve, but applied to a subform.
I also attach a database so you can try it.
Thanks a lot.
Code:
Private Sub CmdAñadirPrecio_Click()
On Error GoTo err_lbl
Dim FechaInicio As Date
Dim FechaFinal As Date
Dim DtoPactado As String
Dim CosteMaquila As String
Dim PrecioContenedor As String
Dim Precio As String
Select Case Screen.PreviousControl.Name
Case "IdTipoDeAceite"
FechaInicio = InputBox("¿Qué fecha de inicio quieres añadir?", NombreBD, Format(Me.Fecha, "Medium date"))
FechaFinal = InputBox("¿Qué fecha final quieres añadir?", NombreBD, Format(Me.Fecha, "Medium date"))
Precio = InputBox("¿Cuál es el precio de este tipo de aceite?", NombreBD)
If Not IsNumeric(Precio) Then Exit Sub
CurrentDb.Execute "INSERT INTO TPreciosAceite (FechaInicio, FechaFinal, IdAlmazara, IdTipoDeAceite," _
& " Precio) VALUES (#" & Format(FechaInicio, "mm/dd/yyyy") & "#, #" & Format(FechaFinal, "mm/dd/yyyy") & "#, " _
& Me.IdAlmazara & ", " & Screen.PreviousControl & ", " & Replace(Precio, ",", ".") & ")"
Case Else
MsgBox "A este campo no se le puede añadir fecha y precio.", vbInformation, NombreBD
Exit Sub
End Select
MsgBox "Precio añadido con éxito.", vbInformation, NombreBD
err_lbl_exit: Exit Sub
err_lbl:
Select Case Err.Number
Case 13 'Error al cancelar la fecha
Exit Sub
End Select
End Sub