Invalid use of null (1 Viewer)

legendv

Registered User.
Local time
Today, 03:46
Joined
Mar 18, 2002
Messages
99
How do you suppress this error? It's occuring when a user types something in a combo box - it doesn't appear in the list - the backspace their entry - then try to leave the combo box. I don't want this error to appear. Anyone know how to suppress that?
 
D

DJN

Guest
Are you using the On Not In List event of the combo box to add the record?
 

legendv

Registered User.
Local time
Today, 03:46
Joined
Mar 18, 2002
Messages
99
No. No records are being added. I'd like to, but don't know how.

Private Sub Combo27_NotInList(NewData As String, Response As Integer)
MsgBox "Please Select A Patient From The List ", vbOKOnly, "Patient Not Listed"
Response = acDataErrContinue
End Sub

Below is what gives me the error when the user types something in that's not in the list then backspaces or clears the combo box and tries to leave the combobox. It gives me the "invalid use of null" error

Private Sub Combo27_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PtKey] = " & Str(Me![Combo27])
Me.Bookmark = rs.Bookmark
End Sub




What am I doing wrong?
 
D

DJN

Guest
Firstly, change the Limit To List property of the combo box to yes. Then copy and paste this code into the On Not In List event procedure.

Private Sub combo27_NotInList(NewData As String, Response As Integer)
On Error GoTo err_combo27_NotInList

Dim strMsg As String
Dim rst As Recordset
Dim db As Database

strMsg = "'" & NewData & "' is not in the list. "
strMsg = strMsg & "Would you like to add it?"

If MsgBox(strMsg, vbOKCancel, "YourFieldName") = vbOK Then

Set db = CurrentDb()
Set rst = db.OpenRecordset("YourTableName")
rst.AddNew
rst!YourFieldName = NewData

rst.Update
Response = acDataErrAdded

rst.Close

End If

exit_combo27_NotInList:

Exit Sub

err_combo27_NotInList:

Err = 0
Resume Next

Else

MsgBox str(Err)
MsgBox Err.Description
Resume exit_combo27_NotInList


End Sub
 

legendv

Registered User.
Local time
Today, 03:46
Joined
Mar 18, 2002
Messages
99
Tried it...

It switched to the VB code and said

User defined type not defined
The heading was highlighted yellow and
the Dim db as Database was highlighted blue

any ideas?

I'd love to be able to do add to a combo box! Any suggestions on what went wrong?

Limit to list is set to Yes
 
Last edited:

Users who are viewing this thread

Top Bottom