Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill form

Status
Not open for further replies.

edgarchado

Technical User
Apr 5, 2005
59
AR
Is there an Easy way to auto fill certain fields in a form from data of a previous record?

In my case I have an order, and I wish to create a new one using data from a previous record. I need this new record to have its own ID, but re use some of the date of a previous record.

It should be able to use the data from any record and not just the previous one.

Thanks.
 
edgarchado,

How do you envision selecting which record to pull the data from if not from the previous record?

Ken S.
 
Using a search form which populates a list box. I plan to search for a specific record which will have the fields I need to reuse.

I would double click on the the record and will send me to a form where I will have some old records and will add the remaining data.

I actually do it with a modification form where I use this search form to access the record and be able to make changes.

The code that I use for this is:

Option Compare Database

Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()

'Constant Select statement for the RowSource
strSQL = "SELECT tblPedido.N°_de_Pedido, tblPedido.Fecha_de_Entrega, tblProductoras.Nombre, tblPedido.Nombre_de_la_Película " & _
"FROM tblProductoras INNER JOIN tblPedido ON tblProductoras.ID_Productora=tblPedido.ID_Productora"

strWhere = "WHERE"

strOrder = " ORDER BY tblPedido.N°_de_Pedido;"


'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtPedido) Then '<--If the textbox txtFName contains no data THEN do nothing
strWhere = strWhere & " (tblPedido.N°_de_Pedido) Like '*" & Me.txtPedido & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If

If Not IsNull(Me.txtFecha) Then
strWhere = strWhere & " (tblPedido.Fecha_de_Entrega) Like '*" & Me.txtFecha & "*' AND"
End If

strWhere = strWhere & " (tblPedido.Fecha_de_Entrega) >= date() And "

strWhere = strWhere & " (tblPedido.Anulado) = False AND "

If Not IsNull(Me.txtProductora) Then
strWhere = strWhere & " (tblProductoras.Nombre) Like '*" & Me.txtProductora & "*' AND"
End If

If Not IsNull(Me.TxtPelicula) Then
strWhere = strWhere & " (tblPedido.Nombre_de_la_Película) Like '*" & Me.TxtPelicula & "*' AND"
End If

'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)

'Pass the SQL to the RowSource of the listbox

Me.lstPedido.RowSource = strSQL & " " & strWhere & "" & strOrder

End Sub

Private Sub lstPedido_DblClick(Cancel As Integer)
'Open frmCustomer based on the ID from lstCustInfo listbox
On Error GoTo Err_lstPedido_DblClick
DoCmd.OpenForm "frmModificarPedido", , , "[N°_de_Pedido] = " & Me.lstPedido, , acDialog
Exit_lstPedido_DblClick:
Exit Sub
Err_lstPedido_DblClick:
MsgBox ("Haga doble click sobre uno de los pedidos")
Resume Exit_lstPedido_DblClick
End Sub

What i would actually need is to rebuild the last part (the double click event) to send only certain data to the new order form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top