Runtime error 2498 - Wrong data type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jalbright1957
    New Member
    • Mar 2016
    • 25

    Runtime error 2498 - Wrong data type

    I have a navigation form with (3) subforms within (1) tab. The customer table in this particular instance is the parent to the customer contacts table. Customer form is a single form, contacts form is a continuous form. Customer table has the PK CompanyID, customer contacts table has the PK ContactID and the FK CustomerID.

    In the footer of the customer contact form there is a button to enter a new contact and selecting it opens a separate form to input a new customer contact. When doing this I get the error "Runtime error 2498 Expression entered is the wrong data type for one of the arguments".

    Below is the Click event to add a contact and the On Load event of the form it is supposed to load:
    Code:
    Private Sub btnAddContact_Click()
    DoCmd.OpenForm "frmAddCompanyContact", , , , acFormAdd, , Me!CompanyID
    End Sub
    Code:
    Private Sub Form_Load()
      If Not IsNull(Me.OpenArgs) And Me.NewRecord Then
          Me!CompanyID = Me.OpenArgs
      End If
    End Sub
  • AdzzzUK
    New Member
    • Dec 2016
    • 1

    #2
    OpenArgs are strings - ie text values. If CompanyID is a numeric value (as I suspect), you need to convert it in your form_load event to the suitable format.

    Comment

    • jalbright1957
      New Member
      • Mar 2016
      • 25

      #3
      I neglected to check what the data type arguments are supposed to be when using openargs and didn't realize it required a text value. Since I'm using the PK (numeric), obviously this wouldn't work. I would rather not go through data conversions so on to a different method. I'm still green with Access and have to look up most methods. Have a better method you can recommend?

      Comment

      Working...