Skip to main content

Data Input by user

I'm trying to add a field to an existing database with a run date keyed in by the user
I'm getting the following error "Error on line 26 - type mismatch"
Does anyone have the answer - The code is as follows:
Sub Main Call TestFunc2()  ' Test different coding examplesEnd Sub
Function TestFunc2' Create the input for Run Date         Dim RunDate As Date         RunDate = InputBox("Enter Run Date MM/DD/YYYY", "Run Date", "") ' Open the  database.          Set db = Client.OpenDatabase("Current_Period.IMD") ' Display the result.          MsgBox "Run Date: " & RunDate ' Create the task.          Set Mgt = db.TableManagement ' Obtain a reference to the table.          Set ThisTable = db.TableDef ' Create a new field.          Set FirstField = ThisTable.NewField ' Configure a new field.          FirstField.Name = "AsOfDate"          FirstField Description = "As of Date"          FirstField.Type = WI_DATE_FIELD          FirstField.Equation = RunDate          FirstField.Length = 10 ' Add the field.          Mgt.AppendField Field       'This is Line 26          Mgt PerformTask          Set Mgt = db.TableManagementEnd Function
 

mohamed Thu, 03/16/2017 - 08:09

Hi Russ,
 
I see 2 issues in the code.
 
1) You are getting "Type Mismatch" error because you are using a different object variable "Field"  instead of using the defined object variable "FirstField" in the line "Mgt.AppendField Field"
 
2) You have to convert the input date string to date using@Ctod function
 
Attached the modified code.
 
Thanks,
Shafeer