Sorry to hear the fires are bad. We had bad fires 50 km from here last
summer. Many lives were lost in the Black Saturday fires.
Here's the code that opens the form where users can choose a part - Note:
parts instead of products. If user is editing the part for this line of the
order detail, the code opens the search form at that part. If user is on a
new record, it opens the search form ready to search for a part.
The code opens the search form in dialog mode so that user is forced to
either choose a part or cancel.
After the user makes their selection the code back in the order detail form
grabs the needed information, closes the search form and continues on to put
the details for the part in the order detail form.
----------------------------
Private Sub cmdGetPart_Click()
Dim strForm As String
Dim frm As Form
Dim lngPartID As Long
Dim strCode As String
Dim strPartCat As String
Dim strBrand As String
Dim strPartDescr As String
Dim strPartSubCat As String
Dim strPartSubSub As String
Dim curCost As Currency
Dim curSell As Currency
Dim dblMarkup As Double
Dim lngSOH As Long
Dim lngLen As Long
Dim strWhere As String
strForm = "frmSearchPartJobSale"
If Len(Me.PartID & vbNullString) > 0 Then
strWhere = "[PartID] = " & Me.PartID
End If
If Len(strWhere & vbNullString) > 0 Then
DoCmd.OpenForm strForm, WindowMode:=acDialog,
WhereCondition:=strWhere
Else
DoCmd.OpenForm strForm, WindowMode:=acDialog
End If
If Len(Me.PartID) > 0 Then
Me.Undo
End If
With Forms(strForm)
lngPartID = .ThePartID
If lngPartID > 0 Then
curCost = Nz(.PriceEachEx, 0)
curSell = Nz(.SalePriceEach, 0)
dblMarkup = Nz(.Markup, 0.25)
strPartCat = Nz(.PartCat, "")
strBrand = Nz(.Brand, "")
strPartDescr = Nz(.PartDescr, "")
strPartSubCat = Nz(.PartSubCat, "")
strPartSubSub = Nz(.PartSubSub, "")
strCode = Nz(.Code, "")
lngSOH = Nz(.TotOH, 0)
End If
End With
DoCmd.Close acForm, strForm
If lngPartID > 0 Then
Me.PartID = lngPartID
If curCost > 0 Then
Me.PriceEachEx = curCost
End If
If curSell > 0 Then
Me.SalePriceEach = curSell
End If
Me.MarkupUsed = IIf(dblMarkup > 0, CStr(dblMarkup * 100) & "%",
Null)
If Len(strPartDescr & vbNullString) > 0 Then
Me!PartDescr = strPartDescr
End If
If Len(strPartCat & vbNullString) > 0 Then
Me!PartCat = strPartCat
End If
If Len(strBrand & vbNullString) > 0 Then
Me!Brand = strBrand
End If
If Len(strPartSubCat & vbNullString) > 0 Then
Me!PartSubCat = strPartSubCat
End If
If Len(strPartSubSub & vbNullString) > 0 Then
Me!PartSubSub = strPartSubSub
End If
If lngSOH > 0 Then
Me.PartID.Tag = lngSOH
Else
Me.PartID.Tag = ""
End If
If Len(strCode & vbNullString) > 0 Then
Me.Code = strCode
End If
If Len(Me.Quantity & vbNullString) > 0 Then
Else
Me.Quantity = 1
End If
Else
Me.Undo
End If
End Sub