Data Type Mismatch Error

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Data Type Mismatch Error

Post by adam »

Hi anyone,

I've set userform initilize event as follows

Code: Select all

Private Sub UserForm_Initialize()
    cboUserName.List = Array("Adam", "Smith")
and to get the user name usding a sql query from access database, im using this line.

Code: Select all

Me.cboUserName.Value = rst![User Name]
But Im geting error message "datatype mismatch in there's no value in the data row of Access table. It works fine if there's data.
is there a way I could avoid this error message if there's no value in column?

Any help would be kindly appreciated.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Data Type Mismatch Error

Post by HansV »

I'm not sure I understand, perhaps

Code: Select all

    If Not IsNull(rst![User Name]) Then
         Me.cboUserName.Value = rst![User Name]
    End If
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Data Type Mismatch Error

Post by adam »

It worked. Thanks for the help.
Best Regards,
Adam