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:
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.