Private Sub cmdInsertBlankLine_Click() On Error GoTo SmartFormError Dim lngOldOrder As Long If Me.NewRecord Then Me.chkBlankLine = True DoCmd.RunCommand acCmdSaveRecord Me.txtOrder = Nz(DMax("iOrder", "tblIngredients", "[iRecipeID]=" & Me![txtRecipeID]), 0) + 1 Else lngOldOrder = Me.txtOrder 'Debug.Print lngOldOrder DoCmd.RunCommand acCmdRecordsGoToNew Me.chkBlankLine = True DoCmd.RunCommand acCmdSaveRecord Me.txtOrder = lngOldOrder DoCmd.RunCommand acCmdSaveRecord Call fReorganize Forms![frmRecipes]![sfrIngredients].Form.Requery End If Exit_SmartFormError: Exit Sub SmartFormError: If Err = 2046 Or Err = 2501 Then Resume Next Else MsgBox Err.Description Resume Exit_SmartFormError End If End Sub
Tips (Main) |
Home |
Function fReorganize() Dim lngNewOrder As Long strSQL = "SELECT iRecipeID, iOrder " & _ "FROM tblIngredients " & _ "WHERE iRecipeID = " & Me.txtRecipeID & " " & _ "ORDER BY iOrder, iBlankLine DESC" Debug.Print strSQL Set rs = CurrentDb.OpenRecordset(strSQL) lngNewOrder = 1 rs.MoveFirst Do Until rs.EOF rs.Edit rs!cdOrder = lngNewOrder lngNewOrder = lngNewOrder + 1 rs.Update rs.MoveNext Loop rs.Close DoCmd.RunCommand acCmdSaveRecord End Function
tblIngredients (Partial list of fields) | ||
iIngredientID | Primary Key - Autonumber | |
iRecipeID | Foreign Key (linked to tblRecipes) - Number, Long | |
iOrder | Number, Long Integer | |
iRemove | Yes/No, Default - False (Optional) | |
iBlankLine | Yes/No, Defualt - False | |
iInstructionsImagePath | Text, 100 |
Private Sub cmdRemoveLine_Click() On Error GoTo cmdRemoveLine_Click_Err Dim intResponse As Integer If Me.NewRecord Then DoCmd.CancelEvent Else intResponse = MsgBox("You are about to DELETE this Line Item, " & vbCrLf & "are you sure?", vbYesNo + vbCritical + vbDefaultButton2, "Delete") If intResponse = vbYes Then DoCmd.SetWarnings False DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True Else ' User chose No. DoCmd.CancelEvent End If End If cmdRemoveLine_Click_Exit: Exit Sub cmdRemoveLine_Click_Err: MsgBox "This Line Item has not been deleted, see Database Administrator!", vbCritical, "Not Deleted" Resume cmdRemoveLine_Click_Exit End Sub
Private Sub cmdInstructions_Click() If DCount("iIngredientID", "tblInstructions", "iIngredientID=" & [txtInstructionID] & " And iAreaID = " & 9) = 0 Then DoCmd.OpenForm "sfrInstructions", , , , acFormAdd Forms![sfrInstructions]![txtIngredientID] = Me.txtInstructionID Forms![sfrInstructions]![txtAreaID] = 9 Forms![sfrInstructions].Caption = "Instructions for " & Nz(Me.cboIngredientID.Column(1), "Enter Instructions or Notes") Else DoCmd.OpenForm "sfrInstructions", , , "iIngredientID=" & [txtInstructionID] & " And iAreaID = " & 9 Forms![sfrInstructions].Caption = "Instructions for " & Nz(Me.cboIngredientID.Column(1), "Enter Instructions or Notes") End If End Sub
DoCmd.RunCommand acCmdSaveRecord If Me.txtInstruction <> "" Then strSQL = "UPDATE tblIngregients " & _ "SET iInstructionsImagePath = "Z:\Recipes\images\noteEdit16.png" " & _ "WHERE iIngredientID=" & Me.txtIngredientID & "" CurrentDb.Execute strSQL, dbFailOnError + dbSeeChanges Else strSQL = "UPDATE tblIngredients " & _ "SET iInstructionsImagePath = "Z:\Recipes\images\noteAdd16.png" " & _ "WHERE iIngredientID=" & Me.txtIngredientID & "" CurrentDb.Execute strSQL, dbFailOnError + dbSeeChanges End If
tblInstructions (Create sfrInstructions from this table, pictured below) | |
iInstructionID | Primary Key - Autonumber |
iIngredientID | Foreign Key (linked to tblIngredients) - Number, Long |
iInstruction | Memo |
iAreaID | Number, Long Integer (Optional) |
iShow | Yes/No, Default - True (Optional) |
frmRecipes (Main Form) | |
cmdUp | Command Button with Up Arrow |
cmdDown | Command Button with Down Arrow |
lstSortDetail | List Box, Visible = No Row Source qrySortIngredients (SQL below) SELECT tblIngredients.iIngredientD, tblIngredients.iRecipeID, tblIngredients.cdOrder FROM tblIngredients WHERE (((tblIngredients.iOrder)>0)) ORDER BY tblIngredients.iOrder; |
sfrIngredients (Subform) | |
cmdRemoveLine | Command Button with Minus Sign |
cmdInsertBlankLine | Command Button with Right Arrow |
cmdInstructions Opens Form sfrInstructions |
Back Style = Transparent and set on top of imgInstructionsImagePath Make sure to *Bring to the Front* so it is on top of the Image Control imgInstructionsImagePath |
imgInstructionsImagePath | Image Control, Control Source = iInstructionsImagePath |
txtOrder | Text Box |
chkBlankLine | Checkbox, Visible = No |
chkRemove | Checkbox, Visible = No (Optional) Use if you only want to Hide the removed line and not delete it. |