Results 1 to 6 of 6
  1. #1
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35

    Run-time Error 2498 - Opening a Form from Another Form

    Hi there,
    I've come across the error shown on the title, which is leaving me perplexed.
    I've been working on this database project for a few days and have been coding everything form by form.
    Today, I decided to create 'form pathing'. What I mean by this (I'm not sure how to call it properly) is to give the users the ability to open certain forms, only after opening the previous forms.

    I have the following main menu form:


    Click image for larger version. 

Name:	_1.png 
Views:	10 
Size:	8.9 KB 
ID:	47927

    If I try to open the form named as Form_frmGestaoOrdensProducao, by click the first button of the main menu, I get the following error:



    Run-time error '2498':
    An expression you entered is the wrong data type for one of the arguments.

    However, if I open the form directly from the database, no error occurs.

    I tried to narrow down as to where the error could be being triggered, but I can't pinpoint it
    From what I gather, the following events are ran (and only once apparently, because after I get the error, I can't debug the events again, unless I reopen the database):


    • The click event for the first button of the main menu


    Code:
    Private Sub btnGestaoOrdensProducao_Click()
    DoCmd.OpenForm Form_frmGestaoOrdensProducao, acNormal
    End Sub

    • The load event for the Form_frmGestaoOrdensProducao form


    Code:
    Private Sub Form_Load()    Dim myDB As Database
        Dim myRS As Recordset
        Dim strSQL As String
        
        Set myDB = CurrentDb
        strSQL = "SELECT CodArtigo FROM tbDicArtigo WHERE IDArtigoTipo = 2"
        
        Set myRS = myDB.OpenRecordset(strSQL, dbOpenSnapshot)
        Set Me.cbArticleCode.Recordset = myRS
        
        myRS.MoveFirst
        Me.cbArticleCode.Value = myRS(0).Value
        varArticleCode = Me.cbArticleCode.Value
        Me.cbArticleCode.SetFocus
        
        Dim totalNumberOfRecords As Integer
        
        Do
            totalNumberOfRecords = totalNumberOfRecords + 1
            Me.dgvProductionOrdersList.Form.Recordset.MoveNext
        Loop Until Me.dgvProductionOrdersList.Form.Recordset.EOF
        
        Me.dgvProductionOrdersList.Form.Recordset.MoveFirst 'Triggers the Current event for the subform
        
        If totalNumberOfRecords > 0 Then
            Me.lblTotalRecords.Caption = "Total de Registos: " & totalNumberOfRecords
        End If
    End Sub 'Proceeds to the GotFocus event of the cbArticleCode Combobox

    • The Current event for the subform inside Form_frmGestaoOrdensProducao form


    Code:
    If Me.IDEstado < 2 Then
            Me.QT.Locked = True
        Else
            Me.QT.Locked = False
        End If
    
    
        If Me.IDEstado = 4 Then
            Me.DataInicio.Locked = True
            Me.DataFim.Locked = True
            
        Else
            Me.DataInicio.Locked = False
            Me.DataFim.Locked = False
        End If
        
        If Me.IDEstado = 2 Then
            Form_frmGestaoOrdensProducao.btnRunProductionOrder.Enabled = True
        Else
            Form_frmGestaoOrdensProducao.btnRunProductionOrder.Enabled = False
        End If
    NOTE: This event is triggered after running the line Me.dgvProductionOrdersList.Form.Recordset.MoveFirs t on the Form_frmGestaoOrdensProducao's load event and after that it goes back to the load event.


    • The GotFocus event of the cbAriticleCode ComboBox


    Code:
    If Me.cbArticleCode.Value = "" Then
            Exit Sub
        End If
        
        Dim myDB As Database
        Dim myRS As Recordset
        Dim strSQL As String
        
        Set myDB = CurrentDb
        strSQL = "SELECT * FROM tbDicArtigo WHERE CodArtigo LIKE '*" & Me.cbArticleCode.Text & "*'"
        
        Set myRS = myDB.OpenRecordset(strSQL, dbOpenSnapshot)
        
        If myRS.RecordCount <> 0 Then
            Me.txtDescription.Value = myRS.Fields(2).Value
            Me.txtClass.Value = myRS.Fields(4).Value
            Me.txtBaseUMC.Value = myRS.Fields(7).Value
            
            varArticleDescription = Me.txtDescription.Value
            varArticleClass = Me.txtClass.Value
            varUMCBase = Me.txtBaseUMC.Value
            
            If myRS.Fields(7).Value = "UN" Then
                Me.Rótulo19.Visible = False
                Me.txtCFQty.Visible = False
                Me.txtCFQty.Value = ""
            Else
                Me.Rótulo19.Visible = True
                Me.txtCFQty.Visible = True
                Me.txtCFQty.Value = myRS.Fields(8).Value
                
                varCFQty = Me.txtCFQty.Value
            End If
            
            Me.txtEANCode.Value = myRS.Fields(12).Value
            Me.txtITFCode.Value = myRS.Fields(13).Value
            
            If Me.txtEANCode.Value <> Null Then
                varEANCode = Me.txtEANCode.Value
            End If
            
            If Me.txtITFCode.Value <> Null Then
                varITFCode = Me.txtITFCode.Value
            End If
        End If
    End Sub
    After running this last event to the end it displays the error message.

    Can anyone help me out as to point me towards what I should be looking for. I'm seriously at a loss here.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    theres no need to loop thru a recordset when you can just ask for the record count:
    Dcount(....)

  3. #3
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35
    Quote Originally Posted by ranman256 View Post
    theres no need to loop thru a recordset when you can just ask for the record count:
    Dcount(....)
    Yes, I know, but since access was being fidgety for no logical reason, as not giving out the correct number of records sometimes, I just went with that way.
    However, that doesn't seem to be related to the problem at hand is it?

  4. #4
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35
    Ok... I must be missing something absurdly simple here...
    I tried to open the other forms from the main menu and I'm getting the same error. The last option on the main menu only opens a very simple form wher the user just has the ability to see a list of recipes and is given the ability to update values on a single column of a subform.

    I'm going to try to simulate the problem by creating a simple form with nothing on it and try to open it...

  5. #5
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35
    Another double post for the sake of closing this thread.
    Well then, what I just realized has left me with more questions than answers...
    From what I gather, the first argument for the DoCmd.OpenForm procedure is implicetly expecting a string and what I was sending was actually a form object, thus the error
    Soooo, in order to get through the error I was getting all that was needed was to change the following:

    THIS

    Code:
    Private Sub btnGestaoOrdensProducao_Click()
       DoCmd.OpenForm Form_frmGestaoOrdensProducao, acNormal
    End Sub
    TO THIS

    Code:
    Private Sub btnGestaoOrdensProducao_Click()
       DoCmd.OpenForm Form_frmGestaoOrdensProducao.Name, acNormal
    End Sub
    Thanks for the time everyone.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    always worth googling the name of the function to find out how it works

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-16-2022, 09:25 AM
  2. Run-time error when opening a new record
    By dhicks in forum Forms
    Replies: 1
    Last Post: 08-01-2018, 02:59 PM
  3. Replies: 4
    Last Post: 01-17-2018, 05:34 PM
  4. Error 2770 when opening a form
    By Abacus1234 in forum Forms
    Replies: 5
    Last Post: 08-27-2016, 01:21 PM
  5. Error In Opening Form
    By cwwaicw311 in forum Forms
    Replies: 1
    Last Post: 03-10-2010, 09:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums