Compile error

  • Thread starter Thread starter Roy Brandon
  • Start date Start date
R

Roy Brandon

This is code I am trying to adapt from another database since I don't know
enough to write it myself. The point is to add a new line to add a repair
item. I THINK the rub is declaring explicit need to changed. But I don't
have a CLUE to what.
Any help is appreciated.
Roy

Option Compare Database
Option Explicit

Private Sub DetParts_LostFocus()
SendKeys "{ESC}"

'Me!JobCode.Undo
'MsgBox "+"

'add new detail record like existing one

Dim strNewRecOrdNum As String
Dim intNewRecRepNum As Integer
Dim intNewRecRepCntNum As Integer

Dim db As database 'This errors out with a COMPILE error

Set db = CurrentDb()
Dim rs As Recordset
Set rs = db.OpenRecordset("Select Top 1 * From OrderDetailTbl
Where orderNumber = '" & Me!OrderNumber & "' And RepairNumber = " &
Me!RepairNumber & " Order By RepairPartCount Desc", dbOpenSnapshot)

db.Execute "Insert Into OrderDetailTbl (orderNumber,
RepairNumber, RepairPartCount) Select '" & Me!OrderNumber & "' as Expr1, " &
Me!RepairNumber + 1 & " as Expr2, " & rs!RepairPartCount & " as Expr3"

strNewRecRoNum = Me!OrderNumber
intNewRecEntryNum = Me!RepairNumber + 1
intNewRecItemNum = rs!RepairPartCount

Me.Requery
Me.RecordsetClone.FindFirst "orderNumber = '" & strNewRecRoNum &
"' And RepairNumber = " & intNewRecEntryNum & " And RepairPartCount = " &
intNewRecItemNum
If Me.RecordsetClone.NoMatch Then
MsgBox "Program error. Can't find new record. Contact
programmer."
GoTo Exit_Pq_LostFocus
End If
Me.Bookmark = Me.RecordsetClone.Bookmark

Exit_Pq_LostFocus:
Set rs = Nothing
Set db = Nothing
Exit Sub

End Sub
 
No, using OPTION EXPLICIT is good coding practice. For one thing, it helps
ensure that you don't mistype variable names.

What you are probably missing is a reference to the DAO library "Microsoft DAO
3.6 Object Library"

You should also change these lines
Dim db As database
Dim rs As Recordset

to

Dim db As DAO.Database
Dim rs As DAO.Recordset


HTH
 
Back
Top