Data Input by user

5 posts / 0 new
Last post
Russ
Offline
Joined: 01/25/2017 - 09:24
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
Offline
Joined: 07/27/2015 - 03:45

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
 
 
 

jyotikumar
Offline
Joined: 04/08/2022 - 02:37

Can you also help me, what changes will be made in the above file"date issue.iss" if its a numeric field?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

That would depend if the numeric field has decimals or not.

jyotikumar
Offline
Joined: 04/08/2022 - 02:37

Yes, It has up to 2 decimals.