I want to create a new table using MapBasic to fill it later with log events. Those log will go in a new table created each year.

Here is my code (error occurs on row with Create Table):

' --- Log
Dim anneelog, pathlog as String

anneelog = Str$(Year(CurDate()))
pathlog = "D:\Partages\Automatisation\Centralisation_DB\log_" & anneelog & ".TAB"
Print anneelog
Print pathlog
Print PathToTableName$(pathlog)

if Not FileExists(pathlog) Then
    Create Table PathToTableName$(pathlog) (Procedure Char(30), PK_POS Integer, PK_enseignes Integer, Enseigne Char(30), Old_Enseigne Char(30), Adresse Char(100), CP Char(12), 
    Country Char(20), Localite Char(50), Surface_IN Float, Secteur Char(30), Sous_Secteur Char(50), X Float, Y Float, User Char(30), Date_modif Date, Heure_modif Time) 
    file pathlog TYPE NATIVE Charset "WindowsLatin1"
    Commit Table PathToTableName$(pathlog) 
    Close Table PathToTableName$(pathlog) 
End if
  • It's generally better to post code as formatted text rather than a screenshot, it makes it easier for others to read and copy paste for testing if required. – T_Bacon Feb 16 '18 at 9:19
  • What version of MapBasic are you using? I think the Time column type was added in later versions. – T_Bacon Feb 16 '18 at 9:27
  • Sorry guys, I am new to this :) I am using MapBasic 16.0 and the Time type is not a problem because the hour of modification displays correctly when my records are saved. The thing is that I'd like to create automatically a new table each year. Unfortunately, I can't create this new table even if the code works when I copy/paste the /Create table/ instruction in the MapBasic window of MapInfo... – AJ23 Feb 16 '18 at 10:26
  • I just tested this with MapBasic v12, changing the path to my local machine, and it worked fine. – T_Bacon Feb 16 '18 at 15:29
  • 2
    Maybe one of your column names match a variable of your? – Peter Horsbøll Møller Feb 19 '18 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.