starting to create a database and new at this. I keep getting the message 'object variable or with block variable not set'. I don't know why I get this error or how to check which line or area in code is wrong. Please help!
Option Compare Database
Option Explicit
Private Sub Save_IP_Type_Button_Click()
On Error GoTo Error_Sub
Dim inputTypeID As Variant
Dim inputType As Variant
inputTypeID = Me!IPTypeID
inputType = Me!IPType
If IsNull(inputTypeID) Then
MsgBox "You must enter an IP acronym!", vbExclamation, "No Acronym Entered"
ElseIf IsNull(inputType) Then
MsgBox "You must enter an IP type!", vbExclamation, "No Type Entered"
Else
Dim table As Recordset
Set table = globalDatabase.OpenRecordset("SELECT * FROM IPTypeLookup WHERE IPTypeID='" & inputTypeID & "';", dbOpenForwardOnly)
If Not table.BOF And table.EOF Then ' If the acronym entered is already in use
table.Close
MsgBox "IP acronym is already in use!", vbExclamation, "Duplicate IP Acronym"
Exit Sub
End If
table.Close
Set table = globalDatabase.OpenRecordset("SELECT * FROM IPTypeLookup WHERE Type='" & inputType & "';", dbOpenForwardOnly)
If table.BOF And table.EOF Then ' If the IP Type entered does not exist
table.Close
Set table = globalDatabase.OpenRecordset("IPTypeLookup", dbOpenTable)
table.AddNew
table!IPTypeID = inputTypeID
table!Type = inputType
table.Update
table.Close
DoCmd.Close acForm, Me.Name
Else ' If the IP Type entered does exist
table.Close
MsgBox "IP type already exists!", vbExclamation, "Duplicate IP Type"
End If
End If
Exit_Sub:
Exit Sub
Error_Sub:
MsgBox err.Description
Resume Exit_Sub
End Sub