ต งให access autonumber ทำให ม 8ต ว

ข้อมูลที่เป็นตัวอักษร หรือตัวอักษรผสมตัวเลข และตัวเลขที่ไม่ใช้ในการคำนวณ เช่น หมายเลขโทรศัพท์ ขนาดจำนวนตัวอักษรที่ใช้ได้ในเขตข้อมูลเท่ากับที่กำหนดในField Size ซึ่งกำหนดได้ไม่เกิน 255 ตัวอักษร โดยโปรแกรมจะนับจำนวนตัวอักษรเท่ามีจริงในเขตข้อมูลของระเบียนนั้น

Memo หรือความจำ เป็นข้อมูลแบบข้อความแบบยาวที่ประกอบด้วยตัวอักษรหรือตัวอักษรกับตัวเลข(ที่ไม่ใช่ข้อมูลแบบไบนารี) จำนวนไม่เกิน 65535 ตัวอักษร ขนาดของเขตข้อมูลของข้อมูลชนิดนี้ขึ้นกับข้อความที่ป้อนเข้าไปโดยจะถูกจำกัดด้วยขนาดของฐานข้อมูล

ข้อมูลประเภท Text และ Memo นั้นมี สัญลักษณ์ในการกำหนดคุณสมบัติด้านรูปแบบ หรือ Format Property ของข้อความทั้งสองแบบ ดังนี้

@ แทนตัวอักษร 1 ตัว หรือการเคาะแป้นวรรค 1 ครั้ง

& แทนตัวอักษร 1 ตัว ถ้าไม่ใส่จะเว้นว่างไว้

< ทำให้ตัวอักษรภาษาอังกฤษทุกตัวในข้อความเป็นตัวพิมพ์เล็ก

\> ทำให้ตัวอักษรภาษาอังกฤษทุกตัวในข้อความเป็นตัวพิมพ์ใหญ่

โดยการกำหนดรูปแบบของข้อความนี้อาจแบ่งเป็น 2 ส่วน (คั่นด้วย เครื่องหมาย ; ) ส่วนแรกเป็นการกำหนดรูปแบบสำหรับข้อความ ส่วนที่สองเป็นการกำหนดสำหรับเมื่อข้อมูลที่ป้อนเป็น ข้อความที่เรียกว่าข้อความที่มีความยาวเป็น 0

พอดีได้ทำโปรเจคเกี่ยวกับ Access เราก็เลยนำเสนอโปรแกรมเกี่ยวกับจัดการบุคคลไป แล้วก็ผ่านแล้ว ล่าสุด ไปพรีเซ้น 25% ไม่ผ่านค่ะ ท้อมาก แทบไม่อยากทำต่อเลย เพราะตัวเองไม่ถนัดอะไรเลย เอาง่ายๆคือ ทำไม่เป็น มาเรียนรู้เพิ่มเติมในอินเทอร์เน็ตก็เหมือนว่าจะไม่เข้าใจเลย ยิ่งเป็นโค้ด VBA ด้วยแล้วยิ่งตายสนิท

คำถามที่ต้องการทราบ (ถามเยอะไปก็ต้องขอโทษด้วยนะคะ ไม่เข้าใจอะไรเลยจริงๆค่ะ) 1.โค้ด VBA Excel สามารถนำไปใช้กับ Access ได้หรือไม่คะ

2.ถ้าเราตั้งค่า ID อะไรก็ตาม ให้เป็น AutoNumber แล้ว เมื่อลบ Record แล้ว อยากให้มันรันเลขเดิมขึ้นมาอ่ะค่ะ เช่น ID 01 ชื่อ..... พอเราลบแล้วบันทึกใหม่ มันกลายเป็น ID 02 อยากให้มันกลับมาเป็น ID 01 เหมือนเดิมนี่ ต้องทำอย่างไรบ้างคะ (ติดมาหลายวันละค่ะปัญหานี้)

3.อยากได้โค้ดที่เกี่ยวกับ จำกัดสิทธิ์ในการเข้าใช้งานโปรแกรม แบบว่า Admin เข้าแก้ไขระบบต่างๆได้ แต่ User ไม่สามารถแก้ไขอะไรได้ ได้แต่บันทึก,แก้ไขข้อมูล,ลบข้อมูล ฯลฯ

4.ช่วยอธิบาย ฟังก์ชั่น คิวรี่ Query แบบเข้าใจง๊ายง่าย ให้ทีค่ะ แล้วมันสามารถทำอะไรได้บ้าง แล้วความสำคัญมัน มากน้อยเพียงใด เอาภาษาบ้านๆเลยก็ได้ค่ะ อย่างทางการเลย ทางการแล้วงง 55555

5.ถ้าคำถามที่ 1 คำตอบคือ OK เราก็สามารถนำโค้ด VBA Excel มาใช้ในการคำนวณเวลาทำงานของพนง.ใน Access ได้ใช่มั้ยคะ

6.ถ้าจะสร้างฟอร์มที่ พอบันทึกข้อมูลแล้ว ข้อมูลก็จะไหลลงมาเรื่อยๆ คล้ายๆ Excel อ่ะค่ะ ต้องสร้างฟอร์มแบบไหนคะ (ที่คิดไว้ คือตารางบันทึกการทำงานของ พนง. ที่เวลาบันทึกปุ๊ป ข้อมูลเก่าไหลลง แล้ว ช่องก็ว่างให้ใส่ข้อมูลใหม่ ประมาณนี้อ่ะค่ะ)

คือจริงๆ ที่มาสอบถาม เพราะมันคิดไม่ออกจริงๆค่ะ บอกตามตรงว่า ทำไม่เป็นเลย ได้แค่เบสิกๆอย่าง สร้างตาราง เชื่อมความสัมพันธ์ สร้างฟอร์มให้มันสามารถลบเพิ่มบันทึกได้ แค่นั้น หรือถ้าใครเก่งๆ พร้อมให้เราสอบถามข้อมูลเกี่ยวกับ Access ได้ตลอดเวลา ทิ้งไอดีไลน์ไว้ให้หน่อยก็ได้ค่ะ หรือสะดวกหลังไมค์ ก็ได้ค่ะ ได้หมดค่ะ ชม.นี้ 55555 (อย่าถือสาเราที่มาตั้งมู้แบบนี้เลยนะคะ เพราะมันคิดไรไม่ออกแล้วจริงๆค่ะ แต่ก็อยากจะลุยงานให้มันเสร็จไวๆ)

ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
คือแบบว่า กำหนด Format autonumber ใน access เป็น 0000 (เพราะมันเป็น autonumber เลยใส่ตัวอักษรไม่ได้...รึเปล่าคะ?) ใน access ก็ขึ้นนะ เช่น 0001, 0002, 0003 แต่พอไปเรียกมาแสดงใน VB.net ขึ้นแค่ 1, 2, 3

พอจะมีวิธีให้นำศูนย์ข้างหน้ามาแสดงมั้ยคะ?

แล้วถ้าจะให้มีตัวอักษรด้วยแบบ E0001, E0002, E0003 จะมีวิธีไหนหรอคะ??

Tag : - - - -

ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ถ้าเป็น ACCESS ให้เอามาเขียนที่ .NET ค่ะ เพราะ Access เน้นใช้ Macro ไม่ค่อยมี build-in function ให้ใช้
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
มีตัว e แล้วมันจะเป็น number ได้ไง

--------

ให้เพิ่มอีก field ไว้เก็บรหัสดีกว่า โดยอ้างอิงจาก autonumber

ส่วนจะเก็บอย่างไร ต้องอาศัยโค้ดของ .net

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
นี่แหละคะประเด็น =w=

ไม่รู้ทำไง พอดีเป็นมือใหม่ VB เพิ่งจะจับไม่ถึงเดือน แฮะๆ

ขอความกรุณาด้วยค่ะ > <

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ขอบคุณค่ะ เขียนแล้วเหมือนกัน แต่ไม่รู้ว่าถูก syntax ป่าว เพราะเขียนเองคะ เหอๆ

Dim conDB As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DataHead.mdb" Dim con As New OleDbConnection(conDB) con.Open()

Dim query As String query = "SELECT CodeAbsent " query &= "FROM tblAbsent ORDER BY CodeAbsent deas"

Val(query) Dim sum As Integer sum = query + 1 Str(query)

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ส่วนนี้เป็น DATA ACCESS LAYER ของ MS ACCESS ค่ะ สร้าง CLASS มาใหม่แล้ว copy แปะ Code (VB.NET)

Imports System Imports System.Data Imports System.Data.OleDb Imports System.IO Imports System.Text Imports System.Collections Imports System.Collections.Generic Imports System.Runtime.CompilerServices '' Simple MsAccess Data Access Layer '' Develop by Proud PNK.R. U. '' Date 21-06-2010 '' Purpose : Provide neccessary method for manipulate Ms Access database through OleDB. '' Some suggestion feature : Can be connect ACCESS 2007 (.ACCDB) and common ACCESS (.MDB) with auto detection. '' But i not yet to test with .MDB ,'coz my machine no have it. > < Namespace OleDbWithMSAccess

Public Enum MSAccessVersionInfo  
    AccessCommon = 1  
    Access2007 = 2
End Enum
Public Class MSAccessConnectionArgs
    Private Const constAccess2007ConnectionStringFrame = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};" _  
        & "Persist Security Info=False;"  
    Private Const constAccess2007ConnectionStringFrameWithUserNameAndPassword = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};" _  
        & "Jet OLEDB:Database Password={1};"
    Private Const constAccessCommonConnectionStringFrame = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};" _  
        & "Persist Security Info=False;"  
    Private Const constAccessCommonConnectionStringFrameWithUserNameAndPassword = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};" _  
        & "User Id=admin;Password={1};"
    Private Const constMsAccessCommandParameterPrefix As String = "@"
    Private _VersionInfo As MSAccessVersionInfo = MSAccessVersionInfo.AccessCommon  
    Private _DataBaseFile As String = String.Empty  
    Private _HasUserName As Boolean = False  
    'Private _UserName As String = String.Empty  
    Private _Password As String = String.Empty
    Public Property VersionInfo() As MSAccessVersionInfo  
        Get  
            Return _VersionInfo  
        End Get  
        Set(ByVal value As MSAccessVersionInfo)  
            _VersionInfo = value  
        End Set  
    End Property  
    Public Property DataBaseFileName() As String  
        Get  
            Return _DataBaseFile  
        End Get  
        Set(ByVal value As String)  
            _DataBaseFile = value  
            If ((_UserName.Length = 0) And (_Password.Length = 0)) Then  
                _HasUserName = False  
            Else  
                _HasUserName = True  
            End If
            'Auto detect version from file extension  
            Dim fileExtension As String = _DataBaseFile.Substring(_DataBaseFile.LastIndexOf("."c) + 1).ToUpper()  
            If (fileExtension.Equals("ACCDB")) Then  
                _VersionInfo = MSAccessVersionInfo.Access2007  
            Else  
                _VersionInfo = MSAccessVersionInfo.AccessCommon  
            End If
        End Set  
    End Property  
    'Public Property UserName() As String  
    '    Get  
    '        Return _UserName  
    '    End Get  
    '    Set(ByVal value As String)  
    '        _UserName = value  
    '        If ((_UserName.Length = 0) And (_Password.Length = 0)) Then  
    '            _HasUserName = False  
    '        Else  
    '            _HasUserName = True  
    '        End If
    '    End Set  
    'End Property  
    Public Property Password() As String  
        Get  
            Return _Password  
        End Get  
        Set(ByVal value As String)  
            _Password = value  
            If (_Password.Length = 0) Then  
                _HasUserName = False  
            Else  
                _HasUserName = True  
            End If  
        End Set  
    End Property  
    Public Property HasUserNameAndPassword() As Boolean  
        Get  
            Return _HasUserName  
        End Get  
        Set(ByVal value As Boolean)  
            _HasUserName = value  
        End Set  
    End Property
    Public Sub New()  
    End Sub
    Public Sub New(ByVal argVersionInfo As MSAccessVersionInfo)  
        Me.VersionInfo = argVersionInfo  
    End Sub  
    Public Sub New(ByVal argVersionInfo As MSAccessVersionInfo, ByVal argDatabaseFileName As String)  
        Me.VersionInfo = argVersionInfo  
        Me.DataBaseFileName = argDatabaseFileName  
    End Sub
    Public Function IsReadyToConnect() As Boolean  
        Return (Me.DataBaseFileName.Length = 0)  
    End Function
    Public Function GetConnectionString() As String  
        Dim retStr As String = String.Empty  
        Dim ConnStr As String = String.Empty
        If (Me.VersionInfo = MSAccessVersionInfo.AccessCommon) Then
            If (Me.HasUserNameAndPassword) Then  
                retStr = String.Format(constAccessCommonConnectionStringFrameWithUserNameAndPassword _  
                                       , Me.DataBaseFileName, Me.Password)  
            Else  
                retStr = String.Format(constAccessCommonConnectionStringFrame _  
                                       , Me.DataBaseFileName)  
            End If  
        Else
            If (Me.HasUserNameAndPassword) Then  
                retStr = String.Format(constAccess2007ConnectionStringFrameWithUserNameAndPassword _  
                                       , Me.DataBaseFileName, Me.Password)  
            Else  
                retStr = String.Format(constAccess2007ConnectionStringFrame _  
                                       , Me.DataBaseFileName)  
            End If
        End If
        Return retStr  
    End Function
End Class
Public Class MsAccessSQLCommandArgs
    Public ConnectionArgs As MSAccessConnectionArgs = New MSAccessConnectionArgs()  
    ''' <summary>  
    ''' Command String with SQL Statement [If you would like to use 'LIKE'   
    ''' operator only wildcard charactor '%' works for any charactor]  
    ''' </summary>  
    ''' <remarks></remarks>  
    '''   
    Public CommandStr As String = String.Empty  
    Public CommandParameters As Hashtable = New Hashtable()
    Public Sub New()
    End Sub
    Public Sub ClearAll()  
        CommandStr = String.Empty  
        CommandParameters = New Hashtable()  
    End Sub
    Public Sub ClearParameters()  
        CommandParameters = New Hashtable()  
    End Sub
    Public Sub AddParameter(ByVal argKey As String, ByVal argValue As Object)  
        CommandParameters.Add(argKey, argValue)  
    End Sub
End Class
Module MsAccessExtension
    Private Const constMsAccessCommandParameterPrefix As String = "@"
    <Extension()> _  
    Public Sub ExecuteCommand(ByVal e As MsAccessSQLCommandArgs)  
        Using myConnection As OleDbConnection _  
            = New OleDbConnection(e.ConnectionArgs.GetConnectionString())
            Dim myCommand As OleDbCommand _  
                = New OleDbCommand(e.CommandStr, myConnection)
            myCommand.CommandType = CommandType.Text
            If (e.CommandParameters.Count > 0) Then
                For Each keyStr As String In e.CommandParameters.Keys  
                    Dim tempKey As String = keyStr  
                    If (Not keyStr.Substring(0, 1).Equals(constMsAccessCommandParameterPrefix)) Then  
                        tempKey = constMsAccessCommandParameterPrefix & tempKey  
                    End If  
                    myCommand.Parameters.AddWithValue(tempKey, e.CommandParameters(keyStr))  
                Next
            End If
            Try  
                myConnection.Open()  
                myCommand.ExecuteNonQuery()  
            Catch ex As Exception  
                Throw New Exception(ex.Message)  
            Finally  
                If Not (myConnection Is Nothing) Then  
                    myConnection.Close()  
                End If  
            End Try
        End Using  
    End Sub
    <Extension()> _  
    Public Function ExecuteCommandScalar(ByVal e As MsAccessSQLCommandArgs) As Object
        Dim oRet As Object = Nothing
        Using myConnection As OleDbConnection _  
            = New OleDbConnection(e.ConnectionArgs.GetConnectionString())
            Dim myCommand As OleDbCommand _  
                = New OleDbCommand(e.CommandStr, myConnection)
            myCommand.CommandType = CommandType.Text
            If (e.CommandParameters.Count > 0) Then
                For Each keyStr As String In e.CommandParameters.Keys  
                    Dim tempKey As String = keyStr  
                    If (Not keyStr.Substring(0, 1).Equals(constMsAccessCommandParameterPrefix)) Then  
                        tempKey = constMsAccessCommandParameterPrefix & tempKey  
                    End If  
                    myCommand.Parameters.AddWithValue(tempKey, e.CommandParameters(keyStr))  
                Next
            End If
            Try  
                myConnection.Open()  
                oRet = myCommand.ExecuteScalar()  
            Catch ex As Exception  
                Throw New Exception(ex.Message)  
            Finally  
                If Not (myConnection Is Nothing) Then  
                    myConnection.Close()  
                End If  
            End Try
            Return oRet
        End Using  
    End Function
    ''' <summary>  
    ''' Return DataTable from MsAccessSQLCommandArgs  
    ''' </summary>  
    ''' <param name="e"></param>  
    ''' <returns></returns>  
    ''' <remarks></remarks>  
    <Extension()> _  
    Public Function GetDataTable(ByVal e As MsAccessSQLCommandArgs) As DataTable
        Dim dtRet As DataTable = New DataTable()
        Using myConnection As OleDbConnection _  
            = New OleDbConnection(e.ConnectionArgs.GetConnectionString())
            Dim myCommand As OleDbCommand _  
                = New OleDbCommand(e.CommandStr, myConnection)
            myCommand.CommandType = CommandType.Text
            If (e.CommandParameters.Count > 0) Then
                For Each keyStr As String In e.CommandParameters.Keys  
                    Dim tempKey As String = keyStr  
                    If (Not keyStr.Substring(0, 1).Equals(constMsAccessCommandParameterPrefix)) Then  
                        tempKey = constMsAccessCommandParameterPrefix & tempKey  
                    End If  
                    myCommand.Parameters.AddWithValue(tempKey, e.CommandParameters(keyStr))  
                Next
            End If  
            Dim myDataAdaptor As OleDbDataAdapter = New OleDbDataAdapter(myCommand)
            Try  
                myConnection.Open()  
                myDataAdaptor.Fill(dtRet)
            Catch ex As Exception  
                Throw New Exception(ex.Message)  
            Finally  
                If Not (myConnection Is Nothing) Then  
                    myConnection.Close()  
                End If  
            End Try
            Return dtRet
        End Using  
    End Function
End Module
End Namespace

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
อยากเข้าใจโค้ดด้วย อันนี้จะรบกวนมากไปรึเปล่าคะ > <

ขอโทษด้วยนะคะ

แล้วก็ขอบคุณสำหรับโค้ดมากค่ะ จะลองดู

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว

ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
code พราวเขียนทดลองค่ะ ว่า method extension จะไปกันได้กับ vb หรือเปล่า สงสัยตรงไหนก้อถามมาดีกว่าค่ะ เรียนแบบอุดมศึกษา ก้อจะประมาณนี้แหละค่ะ

มาดู code ตัวเองอีกที เอ๋อรับทานค่ะ ต้องงี้

Code (VB.NET)

Imports VB.OleDbWithMSAccess Public Class Form1

Private AppConnectionArg As MSAccessConnectionArgs = New MSAccessConnectionArgs()  
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    AppConnectionArg.VersionInfo = MSAccessVersionInfo.Access2007  
    AppConnectionArg.DataBaseFileName = "D:\BIN\Northwind 2007.accdb"         
    Dim IDStr As String = "E" & Counter.ToString("00000")
End Sub
Function NewAutoNumber (ByVal c As MSAccessConnectionArgs ) As String  
    Dim Counter As Integer = 0   
    Dim cmd As MsAccessSQLCommandArgs = New  MsAccessSQLCommandArgs()  
    cmd.ConnectionArgs = c  
    'Field ID มี Type เป็น TEXT นะคะ  
    cmd.CommandStr = "SELECT MAX(ID) FROM [TableName] "  
    Dim tempStr As String = cmd.ExecuteCommandScalar().ToString()  
    Counter = CInt(tempStr.SubString(1)) 'ตัดตัวอักษรออก แล้วเปลี่ยนเป็น integer  
    Counter += 1
    tempStr = "E" + Counter.ToString("000000")  
    Return tempStr         
End Function  
End Class
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว
ต งให access autonumber ทำให ม 8ต ว