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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch 1

Status
Not open for further replies.

PaulChilds

Technical User
May 21, 2002
195
I have created a database for all my movies. On the main form are various fields, including several drop down lists. I have a NotInList procedure setup which says to double click to add a new entry to the list. OnDblClick opens the new mini-form and requeries the records. When I exit the mini-form I can then choose the new entry in the drop down list.

However, if I decide that I made a mistake and wish to re-enter the mini-form, when I double click the box I get a 'Type Mismatch' error. This error will not go away unless I first delete the entry from the box and tab out of it, which is a bit of a pain. Can anyone help.

Below is the code I have used for OnDblClick (the field is called AspRat and the Mini-form is called Asp):

Private Sub AspRat_DblClick(Cancel As Integer)

On Error GoTo Err_AspRat_DblClick
Dim lngAspRat As Long

If IsNull(Me![AspRat]) Then
Me![AspRat].Text = ""
Else
lngAspRat = Me![AspRat]
Me![AspRat] = Null
End If
DoCmd.OpenForm "Asp", , , , , acDialog, "GotoNew"
Me![AspRat].Requery
If lngAspRat <> 0 Then Me![AspRat] = lngAspRat

Exit_AspRat_DblClick:
Exit Sub

Err_AspRat_DblClick:
MsgBox Err.Description
Resume Exit_AspRat_DblClick

End Sub
 
I think the problem is here
If IsNull(Me![AspRat]) Then
Me![AspRat].Text = &quot;&quot;
Else
lngAspRat = Me![AspRat]
Me![AspRat] = Null
End If
If, on the first entry into this function, Me![AspRat] is NULL, you assign &quot;&quot; to it.
Fair enough.
But presumably, when you say &quot;If I change my mind and double-click again&quot;, there is nothing in the combobox, except of course &quot;&quot; which you assigned first time round.
In the else part, which will be executed in this case, you try to assign &quot;&quot; to a long! No go there, I'm afraid. It is indeed a type mismatch.
Why is this part even necessary? If you really want to keep it then you'll need to pass the new value over from the dataentry form and assign it to your combobox after the DoCmd and before the requery. This is not a bad idea anyway.
As an aside, What is the purpose of setting the OpenArgs parameter to &quot;GotoNew&quot;. If this is to ensure that the dataentry form is blank then you might be better off using the parameter designed for this - namely
DoCmd.OpenForm _
FormName:=&quot;Asp&quot;, _
View:=acNormal, _
DataMode:=acFormAdd, _ <-----------
WindowMode:=acDialog
Hope this helps. Raymondo
raymondo@rossar.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top