M
mdbGal
Hello All,
I think this can be done but I'm not sure. I want to be able to transfer
multiple lifts to another table and assign them a new primary key at the same
time, it's not working. I know I am missing something or maybe it really
can't be done this way? I THINK it has to do with the queries that use
transactions. Below is the code I am playing with but can't make it work.
There are lot of lines not in use but I fgured I should post all of the left
that I was playing with.
Dim Msg, Style, Title, Response, MyString
Dim NewMaterialID As Long
Dim rst As Recordset
Dim FileCount As Integer
Dim Counter As Integer
Dim strSQL As String
Set rst = CurrentDb().OpenRecordset("tblMaterialReceiving")
FileCount = DCount("lCoilID", "tblLifts", "[lCoilID]=" &
Me![txtCoilID])
Counter = 0
NewMaterialID = DMax("mrMaterialID", "tblMaterialReceiving") + 1
If Me.chkTransfer = -1 Then
Msg = "You are about to transfer this lift, is that what you
want to do?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Transfer Lift"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
MyString = "Yes"
With rst
Do Until Counter = FileCount
NewMaterialID = DMax("mrMaterialID", "tblMaterialReceiving")
+ 1
.AddNew
'!mrMaterialID = NewMaterialID
'!mrCoilID =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtCoilID]
'!mrReceivedDate = Me.txtTransferDate
'!mrInventoryTransferDate = Date
'!mrTransfer = True
'!mrTransferFrom =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtCustomerID]
'!mrCustomerID = Me.cboTransferTo
'!mrNonConformanceID = Me.txtNonConformanceID
'!mrAlloyID
'!mrTemperID
'!mrGauge
'!mrWidth
'!mrReceivingNumber
'!mrQuantity =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtPieces]
'!mrNetWeight =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtCalculateNet]
'!mrGrossWeight =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtGrossWeight]
.Update
'DoCmd.SetWarnings False
'DoCmd.RunSQL "INSERT INTO tblMaterialReceiving (
mrMaterialID, mrReceivingNumber, mrReceivedDate, mrInventoryTransferDate,
mrTransfer, mrTransferFrom, mrCustomerIdentifier, mrCustomerID, mrLotNumber,
mrAlloyID, mrTemperID, mrGauge, mrWidth, mrQuantity, mrNetWeight,
mrGrossWeight, mrNonConformanceID ) " & _
"SELECT
DMax('mrMaterialID','tblMaterialReceiving')+1, 'S' & [crCoilReceivingNumber],
tblLifts.lTransferDate, tblLifts.lTransferDate, -1,
tblCoilReceiving.crCustomerID, tblLifts.LiftStr, tblLifts.lTransferTo,
tblCoilReceiving.crCoilLotNumber, tblCoilReceiving.crAlloyID,
tblCoilReceiving.crTemperID, tblCoilReceiving.crCoilListGauge,
tblCoilReceiving.crCoilListWidth, tblLifts.lPieces, tblLifts.lCalcNet,
tblLifts.lGrossWeight, tblLifts.lNonConformanceID " & _
"FROM tblCoilReceiving INNER JOIN tblLifts ON
tblCoilReceiving.crCoilID = tblLifts.lCoilID " & _
"WHERE
(((tblLifts.lCoilID)=[Forms]![sfrLiftNonConformance]![txtCoilID]));"
DoCmd.RunSQL "INSERT INTO tblMaterialReceiving (
mrMaterialID, mrReceivingNumber, mrReceivedDate, mrInventoryTransferDate,
mrTransfer, mrTransferFrom, mrCustomerIdentifier, mrCustomerID, mrLotNumber,
mrAlloyID, mrTemperID, mrGauge, mrWidth, mrQuantity, mrNetWeight,
mrGrossWeight, mrNonConformanceID ) " & _
"SELECT " & NewMaterialID & ", 'S' &
[crCoilReceivingNumber], tblLifts.lTransferDate, tblLifts.lTransferDate, -1,
tblCoilReceiving.crCustomerID, tblLifts.LiftStr, tblLifts.lTransferTo,
tblCoilReceiving.crCoilLotNumber, tblCoilReceiving.crAlloyID,
tblCoilReceiving.crTemperID, tblCoilReceiving.crCoilListGauge,
tblCoilReceiving.crCoilListWidth, tblLifts.lPieces, tblLifts.lCalcNet,
tblLifts.lGrossWeight, tblLifts.lNonConformanceID " & _
"FROM tblCoilReceiving INNER JOIN tblLifts ON
tblCoilReceiving.crCoilID = tblLifts.lCoilID " & _
"WHERE
(((tblLifts.lCoilID)=[Forms]![sfrLiftNonConformance]![txtCoilID]));"
.Update
rst.MoveNext 'put in
'rst.MoveFirst 'moved up
DoCmd.RunCommand acCmdSaveRecord
Me.txtStatusID = 7
MsgBox "Be sure to tell the Receiving Department to tag the
Lift with Material Identification number " & NewMaterialID & "!", vbOKOnly,
"Material Receipt"
'DoCmd.SetWarnings True
Counter = Counter + 1
'rst.MoveNext 'put back seems to work best here?
Loop
.Close
End With
'DoCmd.OpenQuery "qupdTransferLifts"
'DoCmd.RunSQL "INSERT INTO tblMaterialReceiving (
mrMaterialID, mrReceivingNumber, mrReceivedDate, mrInventoryTransferDate,
mrTransfer, mrTransferFrom, mrCustomerIdentifier, mrCustomerID, mrLotNumber,
mrAlloyID, mrTemperID, mrGauge, mrWidth, mrQuantity, mrNetWeight,
mrGrossWeight, mrNonConformanceID ) " & _
"SELECT " & NewMaterialID & ", 'S' &
[crCoilReceivingNumber], tblLifts.lTransferDate, tblLifts.lTransferDate, -1,
tblCoilReceiving.crCustomerID, tblLifts.LiftStr, tblLifts.lTransferTo,
tblCoilReceiving.crCoilLotNumber, tblCoilReceiving.crAlloyID,
tblCoilReceiving.crTemperID, tblCoilReceiving.crCoilListGauge,
tblCoilReceiving.crCoilListWidth, tblLifts.lPieces, tblLifts.lCalcNet,
tblLifts.lGrossWeight, tblLifts.lNonConformanceID " & _
"FROM tblCoilReceiving INNER JOIN tblLifts ON
tblCoilReceiving.crCoilID = tblLifts.lCoilID " & _
"WHERE
(((tblLifts.lCoilID)=[Forms]![sfrLiftNonConformance]![txtCoilID]));"
Else
MyString = "No"
DoCmd.CancelEvent
End If
End If
Thanks to all who reply
I think this can be done but I'm not sure. I want to be able to transfer
multiple lifts to another table and assign them a new primary key at the same
time, it's not working. I know I am missing something or maybe it really
can't be done this way? I THINK it has to do with the queries that use
transactions. Below is the code I am playing with but can't make it work.
There are lot of lines not in use but I fgured I should post all of the left
that I was playing with.
Dim Msg, Style, Title, Response, MyString
Dim NewMaterialID As Long
Dim rst As Recordset
Dim FileCount As Integer
Dim Counter As Integer
Dim strSQL As String
Set rst = CurrentDb().OpenRecordset("tblMaterialReceiving")
FileCount = DCount("lCoilID", "tblLifts", "[lCoilID]=" &
Me![txtCoilID])
Counter = 0
NewMaterialID = DMax("mrMaterialID", "tblMaterialReceiving") + 1
If Me.chkTransfer = -1 Then
Msg = "You are about to transfer this lift, is that what you
want to do?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Transfer Lift"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
MyString = "Yes"
With rst
Do Until Counter = FileCount
NewMaterialID = DMax("mrMaterialID", "tblMaterialReceiving")
+ 1
.AddNew
'!mrMaterialID = NewMaterialID
'!mrCoilID =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtCoilID]
'!mrReceivedDate = Me.txtTransferDate
'!mrInventoryTransferDate = Date
'!mrTransfer = True
'!mrTransferFrom =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtCustomerID]
'!mrCustomerID = Me.cboTransferTo
'!mrNonConformanceID = Me.txtNonConformanceID
'!mrAlloyID
'!mrTemperID
'!mrGauge
'!mrWidth
'!mrReceivingNumber
'!mrQuantity =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtPieces]
'!mrNetWeight =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtCalculateNet]
'!mrGrossWeight =
Forms![frmCoilRun]![sfrCoilRun].Form![sfrCoilRunDetail].Form![sfrLifts].Form![txtGrossWeight]
.Update
'DoCmd.SetWarnings False
'DoCmd.RunSQL "INSERT INTO tblMaterialReceiving (
mrMaterialID, mrReceivingNumber, mrReceivedDate, mrInventoryTransferDate,
mrTransfer, mrTransferFrom, mrCustomerIdentifier, mrCustomerID, mrLotNumber,
mrAlloyID, mrTemperID, mrGauge, mrWidth, mrQuantity, mrNetWeight,
mrGrossWeight, mrNonConformanceID ) " & _
"SELECT
DMax('mrMaterialID','tblMaterialReceiving')+1, 'S' & [crCoilReceivingNumber],
tblLifts.lTransferDate, tblLifts.lTransferDate, -1,
tblCoilReceiving.crCustomerID, tblLifts.LiftStr, tblLifts.lTransferTo,
tblCoilReceiving.crCoilLotNumber, tblCoilReceiving.crAlloyID,
tblCoilReceiving.crTemperID, tblCoilReceiving.crCoilListGauge,
tblCoilReceiving.crCoilListWidth, tblLifts.lPieces, tblLifts.lCalcNet,
tblLifts.lGrossWeight, tblLifts.lNonConformanceID " & _
"FROM tblCoilReceiving INNER JOIN tblLifts ON
tblCoilReceiving.crCoilID = tblLifts.lCoilID " & _
"WHERE
(((tblLifts.lCoilID)=[Forms]![sfrLiftNonConformance]![txtCoilID]));"
DoCmd.RunSQL "INSERT INTO tblMaterialReceiving (
mrMaterialID, mrReceivingNumber, mrReceivedDate, mrInventoryTransferDate,
mrTransfer, mrTransferFrom, mrCustomerIdentifier, mrCustomerID, mrLotNumber,
mrAlloyID, mrTemperID, mrGauge, mrWidth, mrQuantity, mrNetWeight,
mrGrossWeight, mrNonConformanceID ) " & _
"SELECT " & NewMaterialID & ", 'S' &
[crCoilReceivingNumber], tblLifts.lTransferDate, tblLifts.lTransferDate, -1,
tblCoilReceiving.crCustomerID, tblLifts.LiftStr, tblLifts.lTransferTo,
tblCoilReceiving.crCoilLotNumber, tblCoilReceiving.crAlloyID,
tblCoilReceiving.crTemperID, tblCoilReceiving.crCoilListGauge,
tblCoilReceiving.crCoilListWidth, tblLifts.lPieces, tblLifts.lCalcNet,
tblLifts.lGrossWeight, tblLifts.lNonConformanceID " & _
"FROM tblCoilReceiving INNER JOIN tblLifts ON
tblCoilReceiving.crCoilID = tblLifts.lCoilID " & _
"WHERE
(((tblLifts.lCoilID)=[Forms]![sfrLiftNonConformance]![txtCoilID]));"
.Update
rst.MoveNext 'put in
'rst.MoveFirst 'moved up
DoCmd.RunCommand acCmdSaveRecord
Me.txtStatusID = 7
MsgBox "Be sure to tell the Receiving Department to tag the
Lift with Material Identification number " & NewMaterialID & "!", vbOKOnly,
"Material Receipt"
'DoCmd.SetWarnings True
Counter = Counter + 1
'rst.MoveNext 'put back seems to work best here?
Loop
.Close
End With
'DoCmd.OpenQuery "qupdTransferLifts"
'DoCmd.RunSQL "INSERT INTO tblMaterialReceiving (
mrMaterialID, mrReceivingNumber, mrReceivedDate, mrInventoryTransferDate,
mrTransfer, mrTransferFrom, mrCustomerIdentifier, mrCustomerID, mrLotNumber,
mrAlloyID, mrTemperID, mrGauge, mrWidth, mrQuantity, mrNetWeight,
mrGrossWeight, mrNonConformanceID ) " & _
"SELECT " & NewMaterialID & ", 'S' &
[crCoilReceivingNumber], tblLifts.lTransferDate, tblLifts.lTransferDate, -1,
tblCoilReceiving.crCustomerID, tblLifts.LiftStr, tblLifts.lTransferTo,
tblCoilReceiving.crCoilLotNumber, tblCoilReceiving.crAlloyID,
tblCoilReceiving.crTemperID, tblCoilReceiving.crCoilListGauge,
tblCoilReceiving.crCoilListWidth, tblLifts.lPieces, tblLifts.lCalcNet,
tblLifts.lGrossWeight, tblLifts.lNonConformanceID " & _
"FROM tblCoilReceiving INNER JOIN tblLifts ON
tblCoilReceiving.crCoilID = tblLifts.lCoilID " & _
"WHERE
(((tblLifts.lCoilID)=[Forms]![sfrLiftNonConformance]![txtCoilID]));"
Else
MyString = "No"
DoCmd.CancelEvent
End If
End If
Thanks to all who reply