Sub b1_mysql抽出goods()
Application.ScreenUpdating = False '画面を固定
Sheets("sheet4").Select 'シートの選択
Range("b1:g10").ClearContents 'シートのクリア
Dim i As Long
Dim mySQL As String
Call a02_InODBC
mySQL = "select * from goods order by com"
Set rs = cn.Execute(mySQL)
If rs.EOF Then
MsgBox "データが、登録されていません"
Else
With rs
'フィールド
For i = 1 To .Fields.Count
Cells(1, i + 1).Value = .Fields(i - 1).Name
Next
'レコード
Range("b2").CopyFromRecordset rs
End With
End If
Call a09_OutODBC
Application.ScreenUpdating = True '画面の固定を解除
End Sub
Sub e2_mysql更新goods()
Dim SelCmd As String '選択用のSQLステートメント
Dim DelCmd As String '削除用のSQLステートメント
Dim n As Integer '注文明細の個数
Dim i As Integer 'カウンタ
'データベースの接続
Call a02_InODBC
'画面を固定
Application.ScreenUpdating = False
'入力したデータ数(b2:b10)を調べる
n = Application.WorksheetFunction.CountA(Range("b2:b30"))
If n = 0 Then
MsgBox "データがないため登録できません", vbOKOnly, "更新"
Exit Sub
End If
'更新登録
For i = 0 To n - 1
ID = Cells(i + 2, 2).Value
cell = Cells(i + 2, 3).Value
cn.Execute ("Update goods Set com = '" & cell & "' Where renban = " & ID & "")
cell = Cells(i + 2, 4).Value
cn.Execute ("Update goods Set name = '" & cell & "' Where renban = " & ID & "")
cell = Cells(i + 2, 5).Value
cn.Execute ("Update goods Set uritan = '" & cell & "' Where renban = " & ID & "")
cell = Cells(i + 2, 6).Value
cn.Execute ("Update goods Set sitan = '" & cell & "' Where renban = " & ID & "")
Next i
'後処理
Call a09_OutODBC
MsgBox "更新されていることを確認して下さい。", vbOKOnly, "更新完了"
'画面の固定を解除
Application.ScreenUpdating = True
End Sub