Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto IDs

Status
Not open for further replies.

wchestnut

Programmer
Aug 9, 2010
79
US
Hello, again!

I have a table with your standard Update window and procedure that works fine. When a new record is created, the ID field is incremented by one in the new record automatically.

Now I have some Embedded code trying to create a new record manually in the same table:

TABLE1:Field1 = TABLE2:Field1
...
ADD(TABLE)

I'm not specifying the TABLE:ID field assuming the system would increment the value automatically. But, the new record is created and the assigned values are saved to each field -- except the ID field which is always 0.

I'm now assuming I have to specify TABLE:ID = -- but to what?
 
Hi

You may use this code in place of add(<tableName>)

Code:
        Access:<tableName>.PrimeAutoInc() 
        Access:<tableName>.Insert()

This should do it

Regards
 
Hello,

That code looks odd to me. I got 4 Syntax Errors when I compiled the program with those recommended changes.

We have Clarion 5. Is that code only supported in a higher version?
 
It should work with Clarion 4 and above , what are the errors you are getting ?

regards



 
Hi!

Just Access:<tableName>.Insert() should be enough as PrimeAutoInc might add a empty row/record.

Regards
 
Okay, here's the code I used:
==============================================================================
! Create New Prospect
! First, check if not flagged Selected or flagged Ignore

IF CO:SalesProspectSelected = 0 OR CO:SalesProspectIgnore = 1
MESSAGE('"' & CLIP(CO:CompanyNameLong) & '" is not flagged as SELECTED or flagged as IGNORE','ERROR: Cannot Create New Prospect')
ELSE
! Select Portfolio
DO SyncWindow
GlobalRequest = SelectRecord
BrowsePortfolioNames
LocalRequest = OriginalRequest
DO RefreshWindow

IF MESSAGE(CLIP(CO:CompanyNameLong) & ' to ' & CLIP(SPORT:Salesperson) & ' - ' & CLIP(SPORT:Name ) & '?','Assign...',ICON:Question,BUTTON:Yes+BUTTON:No,BUTTON:Yes) = BUTTON:Yes

SLSPROSP:portfolioID = SPORT:ID
SLSPROSP:portfolioName = SPORT:Name
SLSPROSP:Salesperson = SPORT:Salesperson

SLSPROSP:CompanyCode = CO:Company
SLSPROSP:CompanyPriority = CO:CoPriority
SLSPROSP:ClientRelationship = '

SLSPROSP:DateAddedtoPortfolio = TODAY()
SLSPROSP:AddedToPortfolioBy = Usr:UserName
SLSPROSP:DateCreated = TODAY()

! ADD(SALESProspects)
Access:SLSPROSPECTS.Insert()


! Update Company, if no Error
IF ERROR() = '
CO:SalesProspectAssigned = 1
CO:SalesProspectAdded = TODAY()
PUT(COMPANY)
END


! GlobalRequest = ChangeRecord
! UpdatePipelineOverview

DISPLAY()
ForceRefresh = True
DO RefreshWindow
END
END
==============================================================================

And here is the compile window results:

Making sales010.obj (sales 010.clw changed)
Making sales010.clw
(sales010.clw 316,37) Syntax error: Field not found:INSERT
(sales010.clw 316,17) Syntax error: Unknown procedure label

 
Hi!

You are using the LEGACY template - Access:<tableName>.Insert() is ABC.

Declare an ALIAS for the SALESProspects and use the ALIAS file to find the next ID. Do a loop check for duplicates in case two users are trying at the same time.

Code:
LOOP
   ADD(SALESProspects)

   IF ERRORCODE() = 43
      <IDColumn> += 1
      CYCLE
   ELSIF ERRORCODE()
      !handle error
   END
   BREAK
END

Regards
 
Hi!

Correction. It should be IF ERRORCODE() = 40 ! DupKeyErr ...

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top