Z
Zedbiker
Hi
My parent form (backpackorder)takes information from a table which lists the
parts used in an asembly. Each part is linked to a subform by its part id
(backpackpartid). The subform contains the order information. When I press a
button on the main form I want to automatically order all the parts. I have
tried to do this using the code below (probably not best way but it sort of
works. Never professed to being a programmer ). It runs through the first
part ok adding the record automatically, then goes to the next part and stops
at the first record.
What am I doing wrong? Msgbox's have been added for error trapping. Many
thanks for any help.
Private Sub CmdOrder_Click()
On Error GoTo Err_CmdOrder_Click
Dim BatchNo As String
Dim ComponentName As String
Dim Priority As String
Dim Signature As String
Dim Quantity As Integer
Dim i As Integer
Dim IDno, IDinc As Integer
DoCmd.GoToRecord , , acLast
IDno = Me![BackPackPartID].Value
MsgBox (IDno)
DoCmd.GoToRecord , , acFirst
IDinc = 1
If IDinc <= IDno Then
IDinc = Me![BackPackPartID].Value
MsgBox (IDinc)
Me![BackPackSubform].SetFocus
DoCmd.GoToRecord , , acLast
BatchNo = Me![BackPackSubform]![Batch]
ComponentName = Me![Component Name]
Quantity = Me![BackPackSubform]![Quantity]
If Me![BackPackPartID] = "1" Then
Signature = Me![CmbSignature].Column(1)
Priority = Me![CmbPriorityLevel].Column(0)
End If
i = CInt(BatchNo)
MsgBox (i)
i = i + 1
BatchNo = CStr(i)
MsgBox (BatchNo)
BatchNo = Format([BatchNo], "000")
MsgBox (BatchNo)
DoCmd.GoToRecord , , acNewRec
Me![BackPackSubform]![Batch] = BatchNo
Me![BackPackSubform]![Component Name] = ComponentName
Me![BackPackSubform]![Signature] = Signature
Me![BackPackSubform]![Priority] = Priority
Me![BackPackSubform]![Quantity] = Quantity
IDinc = IDinc + 1
MsgBox (IDinc)
DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
MsgBox ("Continue?")
End If
Exit_CmdOrder_Click:
Exit Sub
Err_CmdOrder_Click:
MsgBox Err.Description
Resume Exit_CmdOrder_Click
End Sub
My parent form (backpackorder)takes information from a table which lists the
parts used in an asembly. Each part is linked to a subform by its part id
(backpackpartid). The subform contains the order information. When I press a
button on the main form I want to automatically order all the parts. I have
tried to do this using the code below (probably not best way but it sort of
works. Never professed to being a programmer ). It runs through the first
part ok adding the record automatically, then goes to the next part and stops
at the first record.
What am I doing wrong? Msgbox's have been added for error trapping. Many
thanks for any help.
Private Sub CmdOrder_Click()
On Error GoTo Err_CmdOrder_Click
Dim BatchNo As String
Dim ComponentName As String
Dim Priority As String
Dim Signature As String
Dim Quantity As Integer
Dim i As Integer
Dim IDno, IDinc As Integer
DoCmd.GoToRecord , , acLast
IDno = Me![BackPackPartID].Value
MsgBox (IDno)
DoCmd.GoToRecord , , acFirst
IDinc = 1
If IDinc <= IDno Then
IDinc = Me![BackPackPartID].Value
MsgBox (IDinc)
Me![BackPackSubform].SetFocus
DoCmd.GoToRecord , , acLast
BatchNo = Me![BackPackSubform]![Batch]
ComponentName = Me![Component Name]
Quantity = Me![BackPackSubform]![Quantity]
If Me![BackPackPartID] = "1" Then
Signature = Me![CmbSignature].Column(1)
Priority = Me![CmbPriorityLevel].Column(0)
End If
i = CInt(BatchNo)
MsgBox (i)
i = i + 1
BatchNo = CStr(i)
MsgBox (BatchNo)
BatchNo = Format([BatchNo], "000")
MsgBox (BatchNo)
DoCmd.GoToRecord , , acNewRec
Me![BackPackSubform]![Batch] = BatchNo
Me![BackPackSubform]![Component Name] = ComponentName
Me![BackPackSubform]![Signature] = Signature
Me![BackPackSubform]![Priority] = Priority
Me![BackPackSubform]![Quantity] = Quantity
IDinc = IDinc + 1
MsgBox (IDinc)
DoCmd.GoToRecord acDataForm, "BackPackOrder", acGoTo, IDinc
MsgBox ("Continue?")
End If
Exit_CmdOrder_Click:
Exit Sub
Err_CmdOrder_Click:
MsgBox Err.Description
Resume Exit_CmdOrder_Click
End Sub