Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics SL (Archived)

Inserting into Custom Table with Identity Field

(0) ShareShare
ReportReport
Posted on by 40

Solomon v6.5
I have created a custom table using an identity field using the VB Tools
Record maintenance, Field Maintenance, and Generate Schema. In VB tools I am
trying to insert a record into the custom table.  I am not moving any value
to the identity field. 

 The program is putting this error message in the
eventlog: 

System Message 6124: Process started: Wed May 13 08:46 A.M.

 

================================================================================
Processing: Preparing working files
System Message 102: Incorrect syntax near ')'.

 

  Debugging info:
                    dbsqlexec,sInsertFastIO - ExecuteDbProc
 
                    Cursor(csr_xEmailInvStmt) Select * from xEmailInvStmt
 
                    Optional info:
                                   
                  
                  
                    (adminno,belowamtmin,billattn,custid,custstatf

System Message 6127: Error occurred during an abortable transaction. 
Processing
                     will continue.
================================================================================


System Message 6125: Process ended: Wed May 13 08:47 A.M.


If I remove the identy field the insert works fine.  What am I doing
incorrectly.

Here is some additional information that might help.


DROP   TABLE xEmailInvStmt
Go
Print 'Creating table: xEmailInvStmt'
Go

 Create Table xEmailInvStmt (
AdminNo              char (10),
BelowAmtMin          smallint,
BillAttn             char (30),
CustID               char (15),
CustStatFlag         smallint,
DateSent             smalldatetime,
DocType              smallint,
EmailAddr            char (60),
FileName             char (30),
Name                 char (30),
Status               smallint,
User1                char (30),
User2                char (30),
User3                float,
User4                float,
User5                char (10),
User6                char (10),
User7                smalldatetime,
User8                smalldatetime,
VerID                int identity(1,1)
,tstamp Timestamp)
Go

CREATE unique CLUSTERED
  INDEX [xEmailInvStmt0] ON [dbo].[xEmailInvStmt] ([VerID])
WITH
    DROP_EXISTING
ON [PRIMARY]
GO

CREATE
  INDEX [xEmailInvStmt1] ON [dbo].[xEmailInvStmt] ([CustID])
WITH
    DROP_EXISTING
ON [PRIMARY]
GO

 


Option Explicit

Attribute VB_Name = "ModulexEmailInvStmtDH"
Type xEmailInvStmt

AdminNo                             As String * 10
BelowAmtMin                         As Integer
BillAttn                            As String * 30
CustID                              As String * 15
CustStatFlag                        As Integer
DateSent                            As Sdate
DocType                             As Integer
EmailAddr                           As String * 60
FileName                            As String * 30
Name                                As String * 30
Status                              As Integer
User1                               As String * 30
User2                               As String * 30
User3                               As Double
User4                               As Double
User5                               As String * 10
User6                               As String * 10
User7                               As Sdate
User8                               As Sdate
VerID                               As Long

End Type

Global bxEmailInvStmt As xEmailInvStmt, nxEmailInvStmt As xEmailInvStmt

Attribute VB_Name = "xEmailInvStmt_Dhb"
'''''''''''''''''''''''''''''''''''
'jlg - 05-08-2009
' Checked for v6.5
'''''''''''''''''''''''''''''''''''


Option Explicit

Global csr_xEmailInvStmt As Integer
Global err_xEmailInvStmt As Integer
Global mem_xEmailInvStmt As Integer
Global grid_xEmailInvStmt As Integer

Function dbnavfetch_xEmailInvStmt(ctrl As Control, chkstrg As String,
notfoundok As Integer) As Integer
        Dim retval As Integer

        retval = DBNavFetch1(ctrl, csr_xEmailInvStmt, chkstrg,
bxEmailInvStmt, LenB(bxEmailInvStmt))
        If notfoundok Then
                If retval = NOTFOUND Then
                        retval = NoAutoChk
                End If
        End If

        dbnavfetch_xEmailInvStmt = retval
End Function

Sub init_xEmailInvStmt(callsetaddr As Integer, callsqlcursor As Integer,
level As Integer)
        Dim setaddrlevel As Integer

        '  initialize null buffer to eliminate Chr$(0) from strings
        nxEmailInvStmt.CustID = ""
        nxEmailInvStmt.Name = ""
        nxEmailInvStmt.BillAttn = ""
        nxEmailInvStmt.EmailAddr = ""
        nxEmailInvStmt.FileName = ""
        nxEmailInvStmt.AdminNo = ""
        nxEmailInvStmt.User1 = ""
        nxEmailInvStmt.User2 = ""
        nxEmailInvStmt.User5 = ""
        nxEmailInvStmt.User6 = ""


        '  filter cursor flags from level for setaddr()
        setaddrlevel = level And Not (SqlFastReadOnly Or SqlList Or SqlLock
Or SqlNoList Or SqlNoSelect Or SqlReadOnly Or SqlSingleRow Or SqlSystemDb Or
SqlUpdate)

        '  call setaddr()
        If callsetaddr Then
                Call SetAddr(setaddrlevel, "bxEmailInvStmt", bxEmailInvStmt,
nxEmailInvStmt, LenB(bxEmailInvStmt))
        End If

            '  call sqlcursor()
        If callsqlcursor Then
                If level = SqlReadOnly + NOLEVEL Or level = SqlFastReadOnly
+ NOLEVEL Or level = SqlList + NOLEVEL Then
                    Call SqlCursorEx(csr_xEmailInvStmt, level,
"csr_xEmailInvStmt", "xEmailInvStmt", "")
                Else
                    Call SqlCursorEx(csr_xEmailInvStmt, level,
"csr_xEmailInvStmt", "xEmailInvStmt", "xEmailInvStmt")
                End If

        End If

End Sub

Function pvchkfetch_xEmailInvStmt(ctrl As Control, chkstrg As String,
notfoundok As Integer) As Integer
        Dim retval As Integer

        retval = PVChkFetch1(ctrl, csr_xEmailInvStmt, chkstrg,
bxEmailInvStmt, LenB(bxEmailInvStmt))
        If notfoundok Then
                If retval = NOTFOUND Then
                        retval = NoAutoChk
                End If
        End If

        pvchkfetch_xEmailInvStmt = retval
End Function

Function sfetch_xEmailInvStmt() As Integer
        sfetch_xEmailInvStmt = SFetch1(csr_xEmailInvStmt, bxEmailInvStmt,
LenB(bxEmailInvStmt))
End Function

Sub sinsert_xEmailInvStmt()
        Call SInsert1(csr_xEmailInvStmt, "xEmailInvStmt", bxEmailInvStmt,
LenB(bxEmailInvStmt))
End Sub

Function sqlfetch_xEmailInvStmt(sqlstmt As String) As Integer
        sqlfetch_xEmailInvStmt = SqlFetch1(csr_xEmailInvStmt, sqlstmt,
bxEmailInvStmt, LenB(bxEmailInvStmt))
End Function

Sub supdate_xEmailInvStmt()
        Call SUpdate1(csr_xEmailInvStmt, "xEmailInvStmt", bxEmailInvStmt,
LenB(bxEmailInvStmt))
End Sub


'*****Program record insert*****

                    Call TranBeg(True)
                    'initialize cursor
                    err_xEmailInvStmt = sqlfetch_xEmailInvStmt("Select *
from xEmailInvStmt")
                    'insert into db table xEmailInvStmt
                    'clear buffer
                    bxEmailInvStmt = nxEmailInvStmt
                    'bxEmailInvStmt.VerID = 0
                    bxEmailInvStmt.CustID = bCustomer.CustID
                    bxEmailInvStmt.Name = bCustomer.BillName
                    bxEmailInvStmt.BillAttn = bCustomer.BillAttn
                    bxEmailInvStmt.EmailAddr = vEmailAddr
                    bxEmailInvStmt.FileName = FileName
                    bxEmailInvStmt.DocType = 2
                    bxEmailInvStmt.Status = "0"
                    If vDocbal <= 10 Then
                       bxEmailInvStmt.BelowAmtMin = 1
                    Else
                       bxEmailInvStmt.BelowAmtMin = 0
                    End If
                    bxEmailInvStmt.AdminNo = " "
                    bxEmailInvStmt.CustStatFlag = 0
                    bxEmailInvStmt.DateSent = bCustomer.User8
                    sqlstr = "Select * from xt_x0col_pdf where custid = " +
SParm(bCustomer.CustID)
                    serr1 = SqlFetch1(csr_xt_x0col_pdf, sqlstr,
bxt_x0col_pdf, LenB(bxt_x0col_pdf))
                    Do While serr1 <> NOTFOUND
                       If Trim(bxt_x0col_pdf.AdminNo) > "" Then
                          bxEmailInvStmt.AdminNo = bxt_x0col_pdf.AdminNo
                       End If
                       If bxt_x0col_pdf.CustStatFlag > 0 Then
                          bxEmailInvStmt.CustStatFlag =
bxt_x0col_pdf.CustStatFlag
                       End If
                       serr1 = SFetch1(csr_xt_x0col_pdf, bxt_x0col_pdf,
LenB(bxt_x0col_pdf))
                    Loop
                    Call sinsert_xEmailInvStmt
                    Call TranEnd

 

*This post is locked for comments

  • Nayan Mansinha Profile Picture
    1,245 on at
    Re: Re: Re: Inserting into Custom Table with Identity Field

    here's the sample code that lets you INSERT/UPDATE into custom table with identity field:

    1) create custom table such that

    • It has index0
    • identity field is after the tstamp field

    e.g.

    CREATE TABLE [dbo].[xCustMore](
        [custid] [char](15) NOT NULL,
        [f1] [char](10) NULL,
        [f2] [char](40) NULL,
        [tstamp] [timestamp] NOT NULL,
        [ufld] [int] IDENTITY(1,1) NOT NULL,
     CONSTRAINT [xCustMore0] PRIMARY KEY CLUSTERED
        (
            [custid] Asc
        )
    )

     

    2) Add the button to the screen you want to have the above custom fields using customization manager. e.g. Customer maintenance screen can have button called "More Fields..." which brings up VBA standard form (not the solomon one). 

    Private Sub cMore_Click()
        Load UserForm1
       
        Call UserForm1.LoadMoreCustFields(sivMyApp.Controls("ccustid"))
        UserForm1.Show
    End Sub

    here, in the above click routine, LoadMoreCustFields is the public Sub of the standard form which will drive our custom table.

    3) Create DH module file to hold 2 structures: one for insert and another for update that we will perform on our custom table. In the sample below, type xCustMore is used for insert whereas xCustMoreU for update. Note how insert structure excludes the identity column.

    Option Explicit

    Type xCustMore
    custid                              As String * 15
    f1                                  As String * 10
    f2                                  As String * 40

    End Type

    Global bxCustMore As xCustMore, nxCustMore As xCustMore

    Type xCustMoreU
    custid                              As String * 15
    f1                                  As String * 10
    f2                                  As String * 40
    ufld                                As Long
    End Type

    Global bxCustMoreU As xCustMoreU, nxCustMoreU As xCustMoreU

     4) Place desired standard controls on the form with a save button.  Given below is the code for this form:  Note that I have used TextBox1 and TextBox2 to hold the values for f1 and f2 fields that intend to drive.  Also, see the Save click sub as to how insert and update are handled separately.

    Public csr_xCustMore As Integer, newRec As Boolean, csr_xCustMoreU As Integer

    Public Sub LoadMoreCustFields(custid As String)
        Call SqlCursorEx(csr_xCustMore, NOLEVEL, "csr_xCustMore", "xCustMore", "")
       
        Dim i As Integer
       
        newRec = True
        i = SqlFetch1(csr_xCustMore, "SELECT custid, f1, f2 FROM xCustMore WHERE custid = " + SParm(custid), _
            bxCustMore, LenB(bxCustMore))
       
        bxCustMore.custid = custid
        If i <> NOTFOUND Then
            newRec = False
            TextBox1.Text = bxCustMore.f1
            TextBox2.Text = bxCustMore.f2
        Else
            TextBox1.Text = ""
            TextBox2.Text = ""
        End If
    End Sub

    Private Sub btnSave_Click()
        Me.Hide
           
        If newRec Then
            bxCustMore.f1 = TextBox1.Text
            bxCustMore.f2 = TextBox2.Text
            Call TranBeg(True)
            Call SInsert1(csr_xCustMore, "xCustMore", bxCustMore, LenB(bxCustMore))
            Call TranEnd
        Else
            Dim i As Integer, custid As String
           
            custid = bxCustMore.custid
            Call SqlCursorEx(csr_xCustMoreU, NOLEVEL, "csr_xCustMoreU", "xCustMore", "")
            i = SqlFetch1(csr_xCustMoreU, "SELECT * FROM xCustMore WHERE custid = " + SParm(custid), _
                bxCustMoreU, LenB(bxCustMoreU))
           
            bxCustMoreU.f1 = TextBox1.Text
            bxCustMoreU.f2 = TextBox2.Text
           
            Call TranBeg(True)
            Call SUpdate1(csr_xCustMoreU, "xCustMore", bxCustMoreU, LenB(bxCustMoreU))
            Call TranEnd
        End If
    End Sub

     

    Hit me with the questions if things are not clear.

    HTH

  • Community Member Profile Picture
    on at
    Re: Re: Inserting into Custom Table with Identity Field

    I need to add a custom table for the customer screen.  Can you share your code on how you added a custom table in solomon?  You can send it to rrosenhagen@rcsgifts.com if you don't mind.

  • Nayan Mansinha Profile Picture
    1,245 on at
    Re: Re: Re: Inserting into Custom Table with Identity Field

    Have not tried but thinking that may be by excluding Identity field from the Type xEmailInvStmt should get you going!

     HTH

     

     

  • Jamie Gill Profile Picture
    40 on at
    Re: Re: Inserting into Custom Table with Identity Field

    Chris,

     Could not get the Idenity field to work.  We had to change the identity field to primary key 40 Char

    Then we used the following code to generate a unique GUID.

     

    Module1.base

     

    Attribute VB_Name = "Module1"

    Private Type GUID

    Data1 As Long

    Data2 As Integer

    Data3 As Integer

    Data4(7) As Byte

    End Type

     

    Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

     

    Public Function GetGUID() As String

    Dim udtGUID As GUID

    If (CoCreateGuid(udtGUID) = 0) Then

    GetGUID = _

    String(8 - Len(Hex$(udtGUID.Data1)), "0") & Hex$(udtGUID.Data1) & _

    String(4 - Len(Hex$(udtGUID.Data2)), "0") & Hex$(udtGUID.Data2) & _

    String(4 - Len(Hex$(udtGUID.Data3)), "0") & Hex$(udtGUID.Data3) & _

    IIf((udtGUID.Data4(0) < &H10), "0", "") & Hex$(udtGUID.Data4(0)) & _

    IIf((udtGUID.Data4(1) < &H10), "0", "") & Hex$(udtGUID.Data4(1)) & _

    IIf((udtGUID.Data4(2) < &H10), "0", "") & Hex$(udtGUID.Data4(2)) & _

    IIf((udtGUID.Data4(3) < &H10), "0", "") & Hex$(udtGUID.Data4(3)) & _

    IIf((udtGUID.Data4(4) < &H10), "0", "") & Hex$(udtGUID.Data4(4)) & _

    IIf((udtGUID.Data4(5) < &H10), "0", "") & Hex$(udtGUID.Data4(5)) & _

    IIf((udtGUID.Data4(6) < &H10), "0", "") & Hex$(udtGUID.Data4(6)) & _

    IIf((udtGUID.Data4(7) < &H10), "0", "") & Hex$(udtGUID.Data4(7))

    End If

     

    End Function

     

     

     

    USAGE: bsometable.SomeID = GetGUID

    Generated for each new row.

     

    SomeID is char(40).

     

    This generates a unique identity for

    each row.

    Hope this helps.

     

  • Chris Sanderson Profile Picture
    105 on at
    Re: Inserting into Custom Table with Identity Field
    Jamie, Did you ever find a solution for this issue? I am currently working on adding a custom table to our database and have run into the same situation. I am trying to insert a new record, but cannot because the RecordID (my identity field) is automatically assigned 0 when my cursor is initialized. Thank you, Chris

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics SL (Archived)

#1
Community Member Profile Picture

Community Member 136

#2
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 102 Super User 2025 Season 1

#3
REUser Profile Picture

REUser 8

Featured topics

Product updates

Dynamics 365 release plans