カテゴリー
SugiBlog Webエンジニアのためのお役立ちTips

他のフォームを参照する

Form_フォーム.コントロール名.value

などで値を取得できるがインスタンスを生成したほうが簡単で後が楽。

Dim Fm As Form

と、プロシージャ外で変数を定義しておき、

Set Fm = Form_フォーム

でオブジェクトのインスタンスを生成
あとは「Fm.コントロール名.Value」でアクセスできる

2,121 views

配列に値を追加する関数

Private Function array_push(source As Variant, destination As String, flag As Boolean) As String

    Dim Ary() As String
    Dim delimiter As String

    Select Case (flag)
       
        Case True  '選択地域文字列
            delimiter = " "
       
        Case False '選択地域
            delimiter = ":"
   
    End Select

    If InStr(source, destination) < 0 Then
        array_push = source
        Exit Function
    End If

    If Not IsNull(source) Then
        Ary = Split(source, delimiter)
        ReDim Preserve Ary(UBound(Ary) + 1) As String
        Ary(UBound(Ary)) = destination
        array_push = Join(Ary, delimiter)
        array_push = value_splice(array_push, ":")
        DoEvents
        array_push = repRecur(array_push, ":")
    Else
        array_push = destination
    End If

End Function
2,080 views

ファイル名を変更

ファイル名を変更するには、DirectoryクラスのMove()メソッドを使用します。

//現在の名前と新しい名前を引数に指定します。
Directory.Move("Test.txt", "Test.bak");

※但し、異なるボリューム間は移動できない

異なるボリューム間で移動したい場合はFileInfoクラスを使用します。

FileInfo fInfo = new FileInfo ("Test.txt");
fInfo.MoveTo("Test.bak");

※但し、移動先に同名のファイルが存在すればエラーが発生

1,808 views

ACCESSエラー「指定したテーブルから削除できませんでした。」

テーブルにリレーションシップを組んであるため、
削除クエリでレコードを削除できない場合の解決法 

クエリのプロパティで、固有のレコード(UniqueRecords)を「はい」にする

6,837 views

ComboBoxにまとめて値を追加する

string[] str = new string[]{"amanda", "burkley", "circle"};
ComboBox1.Items.AddRange(str);
3,912 views