PDA

View Full Version : combo to inactive products



fabiobarreto10
01-13-2012, 08:02 PM
gentlemen,
I have a form with three combos. Analyst, company and product.
I'm trying to create a fourth combo to inactive products. That is, the company update the combo, a combo shows the products and another shows inactive products.
How do I create a button on the form to send the active product to inactive products.

Eric Frost
01-17-2012, 09:59 PM
You are developing this form in what or how?

fabiobarreto10
01-18-2012, 02:35 AM
Thank you for responding.
I have 3 combos synchronized. That is, a different filter. Analyst, company and product. After the third combo updated, shows the detail of the form.
I have a Yes / No field in the product table. What I'm trying to do is filter the company by the analyst, and then choose between three options: show all products, display products and show active inactive products. Detail in Annex. Can I send the file?

Eric Frost
01-18-2012, 08:26 AM
Sure! Yeah please post the spreadsheet. The more specific explanation you can give the better. You might need to zip the spreadsheet first as the allowed attachments are limited by the extension i.e. I know you can post .zip files, but I don't think you can post .xls files.

fabiobarreto10
01-18-2012, 04:59 PM
Attached. I'm trying to filter out after the first two combos, the third show in the combo according to the chosen option (show all active and inactive).

Thank you.

Eric Frost
01-19-2012, 09:50 AM
Oh, it's Access. Did you write the code that's in there or do you have access to the developer?



Option Compare Database

Private Sub combAnalista_AfterUpdate()

Me.combEmpresa = ""
Me.combProduto = ""
Me.combProduto.RowSource = ""
Me.Section(0).Visible = False
Me.combEmpresa.Visible = True
Me.combProduto.Visible = False
Me.combEmpresa.SetFocus
Me.combEmpresa.RowSource = "SELECT CodEmpresa, NomeDaEmpresa FROM TblEmpresa WHERE CodAnalista=" & Forms!fFiltros!combAnalista & ";"
Me.combEmpresa.Requery
End Sub

Private Sub combAnalista_NotInList(NewData As String, Response As Integer)

Dim sql As String
DoCmd.SetWarnings False
If MsgBox("Analista não cadastrado!" & Chr(13) & Chr(13) & "Deseja cadastrar o Analista " & _
UCase(NewData) & " agora?", vbYesNo, "Cadastro") = vbYes Then
sql = "INSERT INTO TblAnalista(NomeDoAnalista) VALUES ('" & NewData & "')"
DoCmd.RunSQL sql
Response = acDataErrAdded
Else
Response = acDataErrDisplay
End If

End Sub

Private Sub combEmpresa_AfterUpdate()

Me.Section(0).Visible = False
Me.combProduto = ""
Me.combProduto.Visible = True
Me.combProduto.SetFocus
Me.combProduto.RowSource = "SELECT CodProduto, NomeDoProduto FROM TblProduto WHERE CodEmpresa=" & [Forms]![fFiltros]![combEmpresa] & ";"
Me.combProduto.Requery
End Sub

Private Sub combEmpresa_NotInList(NewData As String, Response As Integer)

Dim sql As String
DoCmd.SetWarnings False
If MsgBox("Empresa não cadastrada!" & Chr(13) & Chr(13) & "Deseja cadastrar a Empresa " & _
UCase(NewData) & " agora?", vbYesNo, "Cadastro") = vbYes Then
sql = "INSERT INTO TblEmpresa(NomeDaEmpresa, CodAnalista) VALUES ('" & NewData & "', " & Me.combAnalista & ")"
DoCmd.RunSQL sql
Response = acDataErrAdded
Else
Response = acDataErrDisplay
End If
End Sub

Private Sub combProduto_AfterUpdate()

Dim sql As String
If Me.combProduto.ListIndex = -1 Then Exit Sub
sql = "SELECT *"
sql = sql & " FROM TblProduto"
sql = sql & " Where CodProduto=" & Me.combProduto & ""
Me.RecordSource = sql
Me.Section(0).Visible = True
End Sub

Private Sub combProduto_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub combProduto_NotInList(NewData As String, Response As Integer)
Dim rs As Object, recount As Integer, count As Integer, names As String, rstable As Object, codigo As Integer
Dim CProd As Integer, sql As String
On Error GoTo errorcatch
DoCmd.SetWarnings False
If MsgBox("Produto não cadastrado!" & Chr(13) & Chr(13) & "Deseja cadastrar o Produto " & _
UCase(NewData) & " agora?", vbYesNo, "Cadastro") = vbYes Then
sql = "INSERT INTO TblProduto(NomeDoProduto, CodEmpresa) VALUES ('" & NewData & "', " & Me.combEmpresa & ")"
DoCmd.RunSQL sql
Response = acDataErrAdded
Else
Response = acDataErrDisplay
Exit Sub
End If
DoCmd.SetWarnings True
Set rs = CurrentDb.OpenRecordset("TblProduto Query")
CProd = rs.MaxofCodProduto
rs.Close
Set rs = CurrentDb.OpenRecordset("TblAuxiliarPassos")
Set rstable = CurrentDb.OpenRecordset("TblPassosStatus")
rs.MoveFirst
For count = 1 To 7
codigo = rs.Código
names = rs.NomeDoPasso
With rstable
.AddNew
!CodProduto = CProd
!Passo = codigo
.Update
.Bookmark = .LastModified
End With
rs.MoveNext
Next count
rs.Close
Set rs = Nothing
rstable.Close
Set rstable = Nothing
Me.TblPassosStatus_subformulário.Requery
MsgBox "finished"
Exit Sub
errorcatch:
MsgBox Err.Description
End Sub

Private Sub Form_Open(Cancel As Integer)
MsgBox "Bem vindo!"
Me.Section(0).Visible = False
Me.combAnalista.SetFocus
Me.combEmpresa.Visible = False
Me.combProduto.Visible = False

DoCmd.MoveSize 0, 0, 14750, 10250
End Sub

fabiobarreto10
01-19-2012, 04:02 PM
I got a model and adat. Forgiveness, not to mention that access was previously. You could do directly in db?
Thank you.