First of all I am fairly new to access and self taught. Please let me know if there is an easier or more proper way to do what I am trying to do. Here we go.....
I have a form that is asking for information about the results of a test procedure. One of the comboboxes is asking for which tank the item was tested in (cboTankTestedIn) . There are 3 tanks to choose from (HP1,HP2,HP3). The next 2 comboboxes are the equipment used to test the item (MegType, PIused). Some of the test equipment is always at a certain tank. I would like to limit the selections in the equipment comboboxes based on which tank was tested in. I have a table with all the test equipment in it (tbl_TestEquipment) and a field that signifies that the test equipment is active or not (TestEquipmentInstalled). I have another field that tells the location of the test equipment (TestEquipmentInstalledLocation). I wrote 4 queries to break this down to tank level. The first query pulls out the active equipment for all tanks (qry_TestEquipmentActive). then the other 3 separate the equipment to location being used (qry_TestEquipmentHP1,qry_TestEquipmentHP2,qry_Tes tEquipmentHP3) they are rowsourced to the active equipment query.
please help me I think I might have the code in the wrong place but I am not even sure I am approaching this properly. Thank you for your time and advice!
Here is my code
Code:
Option Compare Database
Private failtoggle As Boolean
Private Sub Form_Activate()
On Error GoTo Form_Open_Err
Me.ProductionItemPartNumber.SetFocus
Exit Sub
Form_Open_Err:
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
End Sub
Private Sub Form_Current()
failtoggle = True
If PassFail Then
tglPassFail.Caption = "Pass"
tglPassFail.Value = 0
Else
tglPassFail.Caption = "Fail"
tglPassFail.Value = -1
End If
failtoggle = False
Select Case cboTankTestedIn
Case Is = "HP1"
Me.MegType.RowSource = qry_TestEquipmentHP1
Me.PIUsed.RowSource = qry_TestEquipmentHP1
Case Is = "HP2"
Me.MegType.RowSource = qry_TestEquipmentHP2
Me.PIUsed.RowSource = qry_TestEquipmentHP2
Case Is = "HP3"
Me.MegType.RowSource = qry_TestEquipmentHP3
Me.PIUsed.RowSource = qry_TestEquipmentHP3
Case Is = ""
MsgBox ("Select Tank Tested in")
Case Is = Null
MsgBox ("Select Tank Tested in")
End Select
End Sub
Private Sub Form_Load()
failtoggle = True
If PassFail Then
tglPassFail.Caption = "Pass"
tglPassFail.Value = 0
Else
tglPassFail.Caption = "Fail"
tglPassFail.Value = -1
End If
failtoggle = False
End Sub
Private Sub NewItem_Click()
On Error GoTo EH
Dim strPartNumber As String
Dim strTech As String
Dim strTestedDate As Date
Dim intTankTestedIn As Integer
Dim intMegger As Integer
Dim intPressure As Integer
strPartNumber = Me.ProductionItemPartNumber
strTech = Me.Technician
strTestedDate = Me.TestedDate
intTankTestedIn = Me.TankTestedIn
intMegger = Me.MegType
intPressure = Me.PIUsed
DoCmd.RunCommand acCmdSaveRecord
'Displays previous records into text box
DispInfo = SerialNumber & "--" & TestedDate & "--" & ProductionItemPartNumber & "--" & tglPassFail.Caption & vbCrLf & vbCrLf & Me.DispInfo.Value
DoCmd.GoToRecord , , acNewRec
ProductionItemPartNumber.SetFocus
Exit Sub
EH:
MsgBox Err.Number & vbCrLf & Err.Description
'frm_DailyTested!SerialNumber.SetFocus
End Sub
Private Sub btnSame_Click()
On Error GoTo EH
Dim strPartNumber As String
Dim strTech As String
Dim strTestedDate As Date
Dim intTankTestedIn As Integer
Dim intMegger As Integer
Dim intPressure As Integer
strPartNumber = Me.ProductionItemPartNumber
strTech = Me.Technician
strTestedDate = Me.TestedDate
intTankTestedIn = Me.TankTestedIn
intMegger = Me.MegType
intPressure = Me.PIUsed
DoCmd.RunCommand acCmdSaveRecord
'Displays previous records into text box
DispInfo = SerialNumber & "--" & TestedDate & "--" & ProductionItemPartNumber & "--" & tglPassFail.Caption & vbCrLf & vbCrLf & Me.DispInfo.Value
DoCmd.GoToRecord acDataForm, "frm_DailyTested", acNewRec
Me.ProductionItemPartNumber = strPartNumber
Me.Technician = strTech
Me.TestedDate = strTestedDate
Me.TankTestedIn = intTankTestedIn
Me.MegType = intMegger
Me.PIUsed = intPressure
SerialNumber.SetFocus
Exit Sub
EH:
MsgBox Err.Number & vbCrLf & Err.Description
'frm_DailyTested!SerialNumber.SetFocus
End Sub
Private Sub tglPassFail_AfterUpdate()
If failtoggle Then Exit Sub
If PassFail Then
tglPassFail.Caption = "Fail"
PassFail = False
Else
tglPassFail.Caption = "Pass"
PassFail = True
End If
End Sub