Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NotinList and Primary key

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi Everyone

I am a form that I would like to run the NotinList event for the reason it is there. The difficulty I have is that the table I am referencing to has 2 fields.

StnID (Primary key)
StationName

What I would like to happen is when there is a record that is NotinList, a message box is displayed and the user has the option to add the record. If yes, a form will open so the record can be added to the table.

I am getting an error after the msgbox saying that the primary key can not be a Null value. The code I am using is:

Private Sub txtStnID_NotInList(NewData As String, Response As Integer)
Dim strsql As String, x As Integer
Dim LinkCriteria As String
x = MsgBox("Do you want to add this value to the list?", vbYesNo)
If x = vbYes Then
strsql = "Insert Into Stations ([Station]) values ('" & NewData & "')"
'MsgBox strsql
CurrentDb.Execute strsql, dbFailOnError
LinkCriteria = "[Stations] = '" & Me!Station.Text & "'"
DoCmd.OpenForm "frmStations", , , LinkCriteria

Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub

Any suggestions to fix this would be great.

Many thanks
tee.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top