仕事でAccessを用いてツールを作成しています。
Accessでは、フォーム幅が限られているため多数の横並びのコントロールの
表示ができません。
なのでExcelみたいにスクロールバーで見える列の移動を変えたいです。
Accessにスクロールバーが無いため、left0の位置からボタンとラベルを作成しtxt1〜txt5のテキストボックスを左から右に並べて配置したものに
対しボタンを移動させるとtxt1,txt2を配置固定としtxt3〜txt5の幅と位置を調整できるように作成しましたが、あきらかに移動値に対し実移動量がおかしいです。
どこが間違っているのか教えてください。
Option Compare Database
Private m_KoumokuTyousei As Boolean
Private m_Koumoku_Width(5) As Double
Private Sub Form_Open(Cancel As Integer)
Dim cnt As Long
cnt = 1
Do
m_Koumoku_Width(cnt) = Me.Controls("txt" & cnt).width
cnt = cnt + 1
Loop Until cnt > 5
End Sub
Private Sub scroll_button_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If m_KoumokuTyousei = True Then Exit Sub
m_KoumokuTyousei = True
Dim Parcent As Long '//スクロールバー値
Dim KaisiKoumoku As Integer '//固定されていない開始フィールド番号
Dim ScrollBar_Parcent As Double
If Button = 1 Then
If Me.scroll_button.width + Me.scroll_button.Left + X > Me.scroll_label.Left + Me.scroll_label.width Then
Me.scroll_button.Left = Me.scroll_label.width - Me.scroll_button.width
Parcent = 100
Else
If Me.scroll_button.Left + X < Me.scroll_label.Left Then
Me.scroll_button.Left = Me.scroll_label.Left
Parcent = 0
Else
Me.scroll_button.Left = Me.scroll_button.Left + X
Parcent = Me.scroll_button.Left / ((Me.scroll_label.width - Me.scroll_button.width) - (Me.scroll_label.Left)) * 100
If Parcent > 100 Then Parcent = 100
End If
End If
Me.scroll_label.Caption = Parcent & "%"
Dim cnt As Long
Dim KoteiKoumoku As Long
Dim Left_Width As Double
Dim Right_Width As Double
Dim Idou_Width As Double
Dim MaxKoumokuSuu As Long
KoteiKoumoku = 2
MaxKoumokuSuu = 5
cnt = 1
Left_Width = 0
Right_Width = 0
'-----------------------------------
Do
If cnt > KoteiKoumoku Then
'//固定項目フィールド以外のフィールドのサイズ取得
Right_Width = Right_Width + m_Koumoku_Width(cnt)
Else
'//固定項目フィールドのサイズ取得
Left_Width = Left_Width + m_Koumoku_Width(cnt)
End If
cnt = cnt + 1
Loop Until cnt > MaxKoumokuSuu
'//移動するサイズ取得
Idou_Width = Right_Width / 100 * Parcent
If X > 0 Then
'左
'//幅設定
cnt = 1
Do
If cnt > MaxKoumokuSuu Then Exit Do
If cnt > KoteiKoumoku Then
If Me.Controls("txt" & cnt).width <> 0 Then
If Idou_Width >= Me.Controls("txt" & cnt).width Then
'//0
Idou_Width = Idou_Width - Me.Controls("txt" & cnt).width
Me.Controls("txt" & cnt).width = 0
Me.Controls("txt" & cnt).Left = Left_Width
Else
'//Idou_Width分引く
Me.Controls("txt" & cnt).width = Me.Controls("txt" & cnt).width - Idou_Width
Me.Controls("txt" & cnt).Left = Left_Width
Exit Do
Idou_Width = 0
End If
End If
End If
cnt = cnt + 1
Loop
'//Left設定
Do
If cnt > MaxKoumokuSuu Then Exit Do
Me.Controls("txt" & cnt).Left = Me.Controls("txt" & cnt - 1).Left + Me.Controls("txt" & cnt - 1).width
cnt = cnt + 1
Loop
Else
'右
cnt = MaxKoumokuSuu
Do
If cnt = KoteiKoumoku Then Exit Do
If Me.Controls("txt" & cnt).width <> 0 Then
'//幅引き伸ばし
If Idou_Width > m_Koumoku_Width(cnt) Then
Idou_Width = Idou_Width - m_Koumoku_Width(cnt)
Me.Controls("txt" & cnt).width = m_Koumoku_Width(cnt)
Else
Me.Controls("txt" & cnt).width = m_Koumoku_Width(cnt) - Idou_Width
Idou_Width = 0
Exit Do
End If
Else
If Me.Controls("txt" & cnt).width <> m_Koumoku_Width(cnt) Then
If Idou_Width > m_Koumoku_Width(cnt) Then
Idou_Width = Idou_Width - m_Koumoku_Width(cnt)
Me.Controls("txt" & cnt).width = m_Koumoku_Width(cnt)
Else
Me.Controls("txt" & cnt).width = m_Koumoku_Width(cnt) - Idou_Width
Idou_Width = 0
Exit Do
End If
End If
End If
cnt = cnt - 1
Loop
'//Left設定
Do
If cnt > MaxKoumokuSuu Then Exit Do
Me.Controls("txt" & cnt).Left = Me.Controls("txt" & cnt - 1).Left + Me.Controls("txt" & cnt - 1).width
cnt = cnt + 1
Loop
End If
End If
m_KoumokuTyousei = False
End Sub