. , , ,

,,,

,

6

.

Sub () . . , , , , . . General, . , , . , , ( ), , , ,

.

, , , .

.

:

Public Function OpenHide(strName As String)

Dim strHide As String

strHide = Screen.ActiveForm.Name

Screen.ActiveForm.Visible = False

DoCmd.OpenForm strName

Screen.ActiveForm.Tag = strHide

End Function

Screen - Microsoft Access 2002. , , .

DoCmd - Microsoft Access 2002. Access Visual Basic.

Visible . True False. .

Tag (Tag). , , . . 2048 . - .

Public Function Close Unhide ()

Dim strUnhide As String

If IsNull (Screen.ActiveForm.Tag) Then

DoCmd.Close

Else

strUnhide = Screen.ActiveForm.Tag

DoCmd.Close

DoCmd.SelectObject acForm, strUnhide

End If

End Function

(SelectObject) ( , ). SelectObject Access, . , , . SelectObject (Visible) , (, ). SelectObject Visual Basic SelectObject DoCmd.

Northwind Products Categories. Categories Products. .

1.      .

2.      Products () . cmdOpenHide Caption () Categories. (OnClick) = OpenHide(Categories)

3.      Categories () . cmdCloseUnhide Caption () . (OnClick) = CloseUnhide()

1

() (). , , . , Tag.

:

. . . , .

, Customers Orders Orders. .

1.      Orders , cmdViewCustomer (View Customer). (OnClick) :

Private Sub cmdViewCustomer_Click()

Dim strForm As String

Dim strWhere As String

strForm = "Customers"

strWhere = "CustomerID = Forms!Orders!CustomerID"

DoCmd.OpenForm FormName:=strForm, wherecondition:=strWhere

End Sub

2.      Orders , Customers, . Orders Customers , .

3.      Customers Orders. Current Customers. , Customers, Form_Current Orders IsLoaded()

Private Sub Form_Current()

Dim strForm As String

Dim strWhere As String

strForm = "Customers"

strWhere = "CustomerID = Forms!Orders!CustomerID"

If IsLoaded(strForm) Then

DoCmd.OpenForm FormName:=strForm, wherecondition:=strWhere

End If

End Sub

Function IsLoaded (ByVal strFormName As String) As Boolean

Const conObjStateClosed = 0

Const conDesignView = 0

If SysCmd (acSysCmdGetObjectState, acForm, strFormName) <>

ConObjStateClosed

Then

If Forms(strFormName).CurrentView <> conDesignView Then

IsLoaded = True

End If

End If

End Function

4.      Orders Customers ( ). Close Orders, Customers, .

Private Sub Form_Close()

Dim strForm As String

strForm = "Customers"

DoCmd.Close acForm, strForm

End Sub

SysCmd ( , , , , ). SysCmd acSysCmdGetObjectState, objecttype (acable, acQuery, acForm, acReport . .) objectname, ( ).

SysCmd acSysCmdGetObjectState .

acObjStateOpen

1

acObjStateDirty

,

2

acObjStateNew

4

, SysCmd 0.

CurrentView Integer.

expression.CurrentView

expression   : Forms!formname,

Forms![form name], Forms("formname")

CurrentView .

0

1

2



Visual Basic MoveSize . .

DoCmd.MoveSize 1440, 2400, , 2000

DoCmd.MoveSize (Right, Down, Width, Height)

Right ( ) .

Down   ( )

Width  .

Height .

2

, , . .

 

 

.

Recordsets.

 

Recordset , SQL , . Recordset OpenRecordset Database Recordsets .

5 Recordset:

1

dbOpenTable

ACCESS. . .

dbOpenSnapshot

, , SQL. .

dbOpenDynaset

, , SQL. .

dbOpenForwardOnly

, , , . . .

dbOpenDynamic

. , , , , , .

Recordset, . OpenRecordset. :

        (, ).

        ( 1).

        , .

       

Recordset . Count . Fields Recordset, rs! ( rs , , Dim rs As DAO.Recordset).

Close Recordset, .

Recordset Field, DAO ADO.

      DAO.

Recordset:

_Database__Connection.OpenRecordset (, []. [], []

OpenRecordset:

dbAppendOnly

Recordset.

.

dbSQLPassThrough

. , .

dbSeeChanges

,

dbDenyWrite

.

dbDenyRead

( Recordset ).

dbForwardOnly

acOpenForwardOnly .

dbReadOnly

.

dbRunAsync

.

dbExecDirect

.

dbInconsistent

.

dbConsistent

.

, . . .

.

 

, , . . . :

        MoveFirst . , Recordset. .

        MoveNext . .

        MovePrevious . .

        MoveLast . .

        Move . .

, . :

        BOF TRUE, .

        EOF TRUE, .

:

1

Dim rs As DAO.Recordset

Dim dbCur As Database

.

Set dbCur=CurrentDb

Set rs=dbCur.OpenRecordset ("Select , FROM "_

& "ORDER BY ", dbOpenSnapshot)

rs.MoveFirst

While Not rs.EOF

CmdEducation.RowSource= CmdEducation.RowSource & rs! & ";" &_

rs! & ";"

rs.MoveNext

Wend

rs.Close

dbCur.Close

2

Dim rs As DAO.Recordset

Dim dbCur As Database, i as integer

.

Set dbCur=CurrentDb

Set rs=dbCur.OpenRecordset (" ", dbOpenDynaset)

If rs.RecordCount <> 0 Then

rs.MoveFirst

For i=1 to rs.RecordCount

'

rs.MoveNext

Next I

End IF

rs.Close

dbCu.Close

RecordCount. . , 1. , , , . , Movelast ( ). RecordCount .

. AbsolutePosition ( 1 RecordCount), PercentPosition , RecordCount ( RecordCount , ).

Recordset.

 

. Recordset Seek, Find. DAO .

Seek , Recordset ( DAO Recordset ). , DAO .

Find.

DAO :

        FindFirst , .

        FindLast , .

        FindNext , .

        FindPrevious , .

, ( Where SQL). NoMatch Recordset. NoMatch FALSE, TRUE.

Find .

        FindFirst .

        FindLast .

        FindNext .

        FindPrevious .

:

VBA , . . Dim . . , , ReDim, .

:

Dim <> ( ) As <>

ReDim <> (<1>[, <2>] . . . )

, ReDim . , , . , Preserve. , .

..

Private Sub cmdFind_Click()

Dim str As String

Dim db As Database

Dim rs As DAO.Recordset

Dim i As Integer

Set db = CurrentDb

Set rs = db.OpenRecordset(" ", dbOpenSnapshot)

If rs.RecordCount = 0 Then

MsgBox " "

Exit Sub

End If

, txtWho

str = " ='" & Forms!!txtWho & "'"

rs.FindFirst str

If rs.NoMatch Then

MsgBox " "

Exit Sub

Else

ReDim Preserve IdList(i)

IdList(i) = rs!

Do Until rs.EOF

rs.FindNext str

If rs.NoMatch = False Then

i = i + 1

ReDim Preserve IdList(i)

IdList(i) = rs!

End If

rs.MoveNext

Loop

End If

rs.Close

db.Close

End Sub

3

, . . 1

. .

Seek.

 

Seek Recordset . . , ( ).

DAO:

.Seek , 1, 2, n

= | >| < | >= | <=


, . . , , . .

, .

Private Sub cmdFind1_Click()_Click()

Dim db As Database

Dim StrFilter As String

Dim rs As DAO.Recordset

Set db = CurrentDb

Set rs = db.OpenRecordset("", dbOpenTable)

rs.Index = "PrimaryKey"

rs.Seek "=", Me!txtOderID

If rs.NoMatch Then

MsgBox " "

Exit Sub

Else

End If

rs.Close

db.Close

End Sub

4

, . .

Recordset.

 

.

DAO :

  1. AddNew, .
  2. .
  3. Update, . , AddNew.

Private Sub New_Click()

Dim rs As DAO.Recordset, dbCur As Database

Set dbCur = CurrentDb

Set rs = dbCur.OpenRecordset("", dbOpenDynaset)

rs.AddNew

rs! = txtNome

rs! = txtNumber

rs! = cmbSex.Column(0)

.................................

rs.Update

rs.Close

dbCur.Close

End Sub

.

DAO :

  1. Edit, .
  2. .
  3. Update .

Private Sub Editrec_Click()

Dim rs As DAO.Recordset, dbCur As Database

Set dbCur = CurrentDb

Set rs = dbCur.OpenRecordset(" ")

rs.MoveFirst

Do Until rs.EOF

If rs! = CInt(Me!txtNumber) Then

rs.Edit

.......................

rs.Update

End If

rs.MoveNext

Loop

rs.Close

dbCur.Close

End Sub

.

 

Delete. , .

.......

Do Until rs.EOF

If rs! = CInt(Me!txtNumber) Then

rs.Delete

End If

rs.MoveNext

Loop

........

: CInt() . Integer.

5

.

, , ( ), . , . , .

6 . Sub () . . ,

 

 

 

! , , , .
. , :