'このVBScriptについて: '【使用方法】 'shouhinnテーブルの商品名の文字数が100バイトに設定されている状態で、 '点検画面等で、超過されている商品名文字数を表示しようとするとエラーになります。 'このスクリプトは、それらをチェックし、修正する為のものです。 'このファイルをダブルクリックして、問題のある点検画面メインIDを指定して下さい。 Dim strUserid Dim strPassword Dim strDsn Dim strConnection Dim Connection Dim rs Dim strSQL Dim Result Dim strShouhinnmei Dim strShouhinnID Dim lFixTargetShouhinnID(50) Dim strFixTargetShouhinnmei(50) Dim counter Dim x Dim strInput Dim strPrompt Dim strTitle Dim lNyushukkaID Dim strInputNyushukkaID strTitle = "商品名文字数修正用マクロ" strInputNyushukkaID = InputBox("問題のある点検画面のメインIDを指定して下さい",strTitle) If IsNumeric(strInputNyushukkaID) = False Then WScript.Quit Else lNyushukkaID = CLng(strInputNyushukkaID) End If If lNyushukkaID > 0 Then 'データベース接続用ID,パスワードの設定 strUserid = "" strPassword = "" strDsn = "Nyushukka" strConnection = "DSN=" & strDsn & "; UID=" & strUserid & "; PWD=" & strPassword counter = 0 'データベース接続 Set Connection = CreateObject("ADODB.Connection") Connection.Open strConnection 'SQL文 strSQL = "select * from nyushukkasub where nyushukkaid = " & lNyushukkaID Set rs = Connection.Execute(strSQL) Do Until rs.EOF = True strShouhinnmei = rs("shouhinnmei") If LenB(strShouhinnmei) > 100 Then lFixTargetShouhinnID(counter) = rs("shouhinnid") strFixTargetShouhinnmei(counter) = rs("shouhinnmei") counter = counter + 1 End If rs.MoveNext Loop Connection.Close 'データベース接続を閉じる x = 0 strPrompt = "文字限度数を超えた商品名を変更して下さい" strTitle = "文字数超過" Do While x < counter strShouhinnID = CStr(lFixTargetShouhinnID(x)) strShouhinnmei = strFixTargetShouhinnmei(x) strInput = InputBox(strPrompt,strTitle,strShouhinnmei) Do While LenB(strInput) > 100 strInput = InputBox(strPrompt,strTitle,strShouhinnmei) Loop Set Connection = CreateObject("ADODB.Connection") Connection.Open strConnection strSQL = "UPDATE nyushukkasub SET shouhinnmei = '" & strInput & "' WHERE (nyushukkaid = " & CStr(lNyushukkaID) & ") AND (shouhinnid = " & strShouhinnID & ")" Connection.BeginTrans Connection.Execute strSQL If Err.Number = 0 Then Connection.CommitTrans Connection.Close MsgBox "nyushukkasubテーブルの情報を更新しました",MB_ICONINFORMATION,strTitle Else MsgBox "情報の修正に失敗しました",MB_ICONINFORMATION,strTitle Connection.RollbackTrans Connection.Close Exit Do End If Set Connection = CreateObject("ADODB.Connection") Connection.Open strConnection strSQL = "UPDATE shouhinn SET shouhinnmei = '" & strInput & "' WHERE shouhinnid = " & strShouhinnID Connection.BeginTrans Connection.Execute strSQL If Err.Number = 0 Then Connection.CommitTrans Connection.Close MsgBox "shouhinnテーブルの情報を更新しました",MB_ICONINFORMATION,strTitle Else MsgBox "情報の修正に失敗しました",MB_ICONINFORMATION,strTitle Connection.RollbackTrans Connection.Close Exit Do End If x = x + 1 Loop End If Set rs = Nothing Set Connection = Nothing MsgBox "処理が終了しました",MB_ICONINFORMATION,strTitle