Hello,
I'm working on a search form. I have 3 combo boxes and I want to find combinations on a query to later show it in a report. Perhaps this is too complicated but I don't know how else to do it. I thought this code worked at first, but then a realized it wasn't really working. I know something is up with the if statements but I don't know how to fix it.
I really appreciate the help!
I'm working on a search form. I have 3 combo boxes and I want to find combinations on a query to later show it in a report. Perhaps this is too complicated but I don't know how else to do it. I thought this code worked at first, but then a realized it wasn't really working. I know something is up with the if statements but I don't know how to fix it.
Code:
Private Sub Findbtm_Click() If Me.CompanyCell.Value = "" Then Beep Select Case MsgBox("Cell Company is required", vbOK) Case vbOK: 'do nothing Case Else: 'do nothing End Select Else Me.cellbox = Me.CompanyCell Me.newcell = Me.CompanyCell Me.firstflux = Me.Companyflux Me.firstribbon = Me.CompanyRibbon If [firstflux] = [company name] And [firstribbon] = [Ribbon Company] Then MsgBox ("firstflux<>companyname and firstribbon<>ribbon company") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo ElseIf [firstflux] = "" And [firstribbon] = "" Then MsgBox ("firstflux="" and firstribbon=""") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo ElseIf [firstflux] = [company name] And [firstribbon] = "" Then MsgBox ("firstflux=companyname and firstribbon=""") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo ElseIf [firstflux] = "" And [firstribbon] = [Ribbon Company] Then MsgBox ("firstflux="" and firstribbon=ribbon company") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo Else Beep Select Case MsgBox("Combination not found. Would you like possible combinations?", vbYesNo) Case vbYes: 'finds possible combinations Me.newcell = Me.CompanyCell Beep Select Case MsgBox("Would you like to make Flux unknown?", vbYesNo) Case vbYes: 'Makes flux company unknown Me.Companyflux.Value = "" Me.newflux = Me.Companyflux Case vbNo: 'leaves flux company as it is Me.newflux = Me.Companyflux Case Else: 'default case to trap any errors 'do nothing End Select Beep Select Case MsgBox("Would you like to make Ribbon unknown?", vbYesNo) Case vbYes: 'makes ribbon company unknown Me.CompanyRibbon.Value = "" Me.newribbon = Me.CompanyRibbon Case vbNo: 'leaves ribbon company as it is Me.newribbon = Me.CompanyRibbon Case Else: 'defaul case to trab any errors 'do nothing End Select If [newflux] = "" And [newribbon] = "" Then MsgBox ("newflux="" and newribbon=""") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo ElseIf [newflux] = [company name] And [newribbon] = [Ribbon Company] Then MsgBox ("newflux=companyname and newribbon=ribbon company") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo ElseIf [newribbon] = [Ribbon Company] Then MsgBox ("newribbon=ribbon company") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo ElseIf [newflux] = [company name] Then MsgBox ("newflux=companyname") DoCmd.OpenQuery "Sales", acViewNormal DoCmd.OpenReport "sales", acViewReport DoCmd.Close acForm, "sales", acSaveNo Else Beep Select Case MsgBox("Combination not found. Would you like to add a New Product?", vbYesNo) Case vbYes: 'opens new product "entry form" and closes "sales" form DoCmd.OpenForm "entry form" DoCmd.Close acForm, "sales", acSaveNo DoCmd.Close acQuery, "sales", acSaveNo DoCmd.Close acReport, "sales", acSaveNo Case vbNo: 'closes "sales" form and goes to "main menu" DoCmd.OpenForm "main menu" DoCmd.Close acForm, "sales", acSaveNo DoCmd.Close acQuery, "sales", acSaveNo DoCmd.Close acReport, "sales", acSaveNo Case Else: 'do nothing End Select End If Case vbNo: 'Do nothing Case Else: 'Default case to trap any errors 'Do nothing End Select End If End If End Sub
Comment