di event on click button itu tinggalkan masukkan nama fungsinya:

sub button1_click()
    call buattabledetail()
end sub

aksan kurdin



On 7/15/2010 10:48 AM, Rusmanto wrote:

Dear temen-temen,

Saya mau Tanya saya dulu dikasih module sama Bang Sofyan seperti ini :

Public Function BuatTableDetail()

'Membuat table detail

'Dibuat oleh Sofyan Efendi, (c) 2006, all rights reserved.

'Untuk Rusmanto

    Dim db As DAO.Database

    Dim rs As DAO.Recordset

    Dim j As Long, jml As Integer

    Dim strSQL As String

    Dim HoleID As String

    Dim NilaiAkhir As Double

    Set db = CurrentDb()

    Set rs = db.OpenRecordset("TableA", dbReadOnly)

    rs.MoveFirst

    DoCmd.SetWarnings False

    Do While rs.EOF = False

        HoleID = rs![hole_id]

        NilaiAkhir = rs![t_depth]

        jml = Int(NilaiAkhir) + 1

        For j = 1 To jml

            If j = jml Then

strSQL = "INSERT INTO [TableB] ( hole_id, [from], [to] )" _

& " SELECT [TableA].hole_id," & j - 1 & " AS [from], [TableA].t_depth" _

& " FROM [TableA]" _

& " WHERE [TableA].hole_id = '" & HoleID & "';"

            Else

strSQL = "INSERT INTO [TableB] ( hole_id, [from], [to] )" _

& " SELECT [TableA].hole_id," & j - 1 & " AS [from], " & j & " AS [to]" _

& " FROM [TableA]" _

& " WHERE [TableA].hole_id = '" & HoleID & "';"

            End If

            DoCmd.RunSQL strSQL

        Next j

        rs.MoveNext

Loop

    DoCmd.SetWarnings True

    rs.Close

    db.Close

    Set rs = Nothing

    Set db = Nothing

End Function

Nah saya mau module ini disimpan di button pada form tertentu gimana caranya yah.

Makasih

Salam

Rusman



Kirim email ke