ACCESS で Openarg s を使う


Private Sub cmdShow2_Click()

On Error GoTo Err_cmdShow_Click

Dim stDocName As String

stDocName = "F応援月報"

Dim Y As Integer
Dim m As String
Dim C As String
Dim Arg As String

Y = Me.年
m = Format(Me.月, “00”)
C = Format(Me.会社ID, “0000”)
Arg = Y & m & C

DoCmd.OpenForm stDocName, , , , , , Arg

Exit_cmdShow_Click:
Exit Sub

Err_cmdShow_Click:
MsgBox err.Description
Resume Exit_cmdShow_Click

End Sub

開かれるフォームの側


Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then

Me.cboNEN = CInt(Left(OpenArgs, 4))
Me.cboMONTH = CInt(Mid(OpenArgs, 5, 2))
Me.cboENC = CInt(Right(OpenArgs, 4)) →会社コードとしてENCを使用
Else

Me.cboNEN = Year(Date)
Me.cboMONTH = Month(Date)
Me.cboENC = Null

End If

Me.よみ_C = Null

Me.Requery

Me.cmdRef.SetFocus

End Sub