I am stumped with this one, I have been trying to work out what is wrong for a few hours, but need some help please.
The code is as follows.
Private Sub TxtGoto_AfterUpdate()
On Error GoTo Err_Handler
Me.StockSuccess.Visible = False
MsgBox "before ifs"
If (TxtGoto & vbNullString) = vbNullString Then Exit Sub
Dim db As DAO.Database
Dim rsCheckStock As DAO.Recordset
Set db = CurrentDb
Set rsCheckStock = db.OpenRecordset("tblStockDetail")
rsCheckStock.FindFirst "[BarcodeNumber]=" & TxtGoto
MsgBox rsCheckStock!BarcodeNumber.Value
If rsCheckStock.NoMatch Then
MsgBox "Sorry, no such record '" & TxtGoto & "' was found in stock. Check the Production Database.", vbOKOnly + vbInformation: TxtGoto.SetFocus
Else
MsgBox "set bookmark"
Me.Recordset.Bookmark = rsCheckStock.Bookmark
'Check item should be in this location
If (rsCheckStock!Location.Value) <> (Me!cbLocationCode.Value) Then
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' should not be in this location, Move it into Quaranteed, and the put it into the correct location! "
Me.StockSuccess.ForeColor = vbRed
Me.StockSuccess.BorderColor = vbRed
Me.StockSuccess.Visible = True
MsgBox "Sorry, the Barcode Number '" & Me.BarcodeNumber & "' Is in the Wrong Location!.", vbOKOnly + vbInformation
TxtGoto = Null
TxtGoto.SetFocus
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit Sub
ElseIf (rsCheckStock!StockTakeRef.Value) = (Me!TxtStockTakeRef.Value) Then
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' has already been entered onto this stock take!! "
Me.StockSuccess.ForeColor = vbRed
Me.StockSuccess.BorderColor = vbRed
Me.StockSuccess.Visible = True
MsgBox "Sorry, the Barcode Number '" & Me.BarcodeNumber & "' has already been entered onto this stock take!.", vbOKOnly + vbInformation
TxtGoto = Null
TxtGoto.SetFocus
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit Sub
ElseIf (rsCheckStock!SoldDate.Value & vbNullString) <> vbNullString Or (rsCheckStock!CustomerSoldTo.Value & vbNullString) <> vbNullString Or _
(rsCheckStock!DespatchNote.Value & vbNullString) <> vbNullString Then
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' has already been sold, It should not be here! "
Me.StockSuccess.ForeColor = vbRed
Me.StockSuccess.BorderColor = vbRed
Me.StockSuccess.Visible = True
MsgBox "Sorry, the Barcode Number '" & Me.BarcodeNumber & "' has already been sold, contact Sales!.", vbOKOnly + vbInformation
TxtGoto = Null
TxtGoto.SetFocus
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit Sub
Else
'update StockDetails file with StockTakeRef
rsCheckStock.Edit
rsCheckStock!StockTakeRef.Value = Me.TxtStockTakeRef
rsCheckStock.Update
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' has been added to the Stock Take!"
Me.StockSuccess.ForeColor = vbGreen
Me.StockSuccess.BorderColor = vbGreen
Me.StockSuccess.Visible = True
TxtGoto = Null
TxtGoto.SetFocus
End If
End If
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit_Err:
Exit Sub
Err_Handler:
MsgBox Err.Number & Err.Description
Resume Exit_Err
TxtGoto = Null
End Sub
I am sure this was working, but it was late at night when I was writing it, so cant quite remember. If the txtGoto doesn't exist in the tblStockDetail , if works to that point. However as soon as txtGoto exists I get the 3159: Not a valid bookmark error.
Any help will be fantastic.
Thanks,
Rob.
The code is as follows.
Private Sub TxtGoto_AfterUpdate()
On Error GoTo Err_Handler
Me.StockSuccess.Visible = False
MsgBox "before ifs"
If (TxtGoto & vbNullString) = vbNullString Then Exit Sub
Dim db As DAO.Database
Dim rsCheckStock As DAO.Recordset
Set db = CurrentDb
Set rsCheckStock = db.OpenRecordset("tblStockDetail")
rsCheckStock.FindFirst "[BarcodeNumber]=" & TxtGoto
MsgBox rsCheckStock!BarcodeNumber.Value
If rsCheckStock.NoMatch Then
MsgBox "Sorry, no such record '" & TxtGoto & "' was found in stock. Check the Production Database.", vbOKOnly + vbInformation: TxtGoto.SetFocus
Else
MsgBox "set bookmark"
Me.Recordset.Bookmark = rsCheckStock.Bookmark
'Check item should be in this location
If (rsCheckStock!Location.Value) <> (Me!cbLocationCode.Value) Then
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' should not be in this location, Move it into Quaranteed, and the put it into the correct location! "
Me.StockSuccess.ForeColor = vbRed
Me.StockSuccess.BorderColor = vbRed
Me.StockSuccess.Visible = True
MsgBox "Sorry, the Barcode Number '" & Me.BarcodeNumber & "' Is in the Wrong Location!.", vbOKOnly + vbInformation
TxtGoto = Null
TxtGoto.SetFocus
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit Sub
ElseIf (rsCheckStock!StockTakeRef.Value) = (Me!TxtStockTakeRef.Value) Then
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' has already been entered onto this stock take!! "
Me.StockSuccess.ForeColor = vbRed
Me.StockSuccess.BorderColor = vbRed
Me.StockSuccess.Visible = True
MsgBox "Sorry, the Barcode Number '" & Me.BarcodeNumber & "' has already been entered onto this stock take!.", vbOKOnly + vbInformation
TxtGoto = Null
TxtGoto.SetFocus
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit Sub
ElseIf (rsCheckStock!SoldDate.Value & vbNullString) <> vbNullString Or (rsCheckStock!CustomerSoldTo.Value & vbNullString) <> vbNullString Or _
(rsCheckStock!DespatchNote.Value & vbNullString) <> vbNullString Then
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' has already been sold, It should not be here! "
Me.StockSuccess.ForeColor = vbRed
Me.StockSuccess.BorderColor = vbRed
Me.StockSuccess.Visible = True
MsgBox "Sorry, the Barcode Number '" & Me.BarcodeNumber & "' has already been sold, contact Sales!.", vbOKOnly + vbInformation
TxtGoto = Null
TxtGoto.SetFocus
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit Sub
Else
'update StockDetails file with StockTakeRef
rsCheckStock.Edit
rsCheckStock!StockTakeRef.Value = Me.TxtStockTakeRef
rsCheckStock.Update
Me.StockSuccess.Caption = "Item with Barcode : '" & Me.BarcodeNumber & "' has been added to the Stock Take!"
Me.StockSuccess.ForeColor = vbGreen
Me.StockSuccess.BorderColor = vbGreen
Me.StockSuccess.Visible = True
TxtGoto = Null
TxtGoto.SetFocus
End If
End If
rsCheckStock.Close
Set rsCheckStock = Nothing
db.Close
Set db = Nothing
Exit_Err:
Exit Sub
Err_Handler:
MsgBox Err.Number & Err.Description
Resume Exit_Err
TxtGoto = Null
End Sub
I am sure this was working, but it was late at night when I was writing it, so cant quite remember. If the txtGoto doesn't exist in the tblStockDetail , if works to that point. However as soon as txtGoto exists I get the 3159: Not a valid bookmark error.
Any help will be fantastic.
Thanks,
Rob.