text5 Forms!Form3!text5
이라는 텍스트 상자를 채우는 코드가 있습니다. 하지만이 텍스트 상자를 업데이트하는 버튼을 클릭 할 때마다 새로 고칩니다.MS Access 텍스트 상자 업데이트/추가
텍스트를 고정시키고 버튼을 클릭 할 때마다 새 데이터를 추가하고 싶습니다. 당신이 strResult
의 값이 텍스트 상자에 전달되고 난 그냥 다시 시작 후에도 텍스트 상자에 값을 계속 추가 할 볼 수 있듯이 지금까지
Option Compare Database
Private Sub Command0_Click()
Set db = CurrentDb
Dim I As Integer
Dim varNumber As Integer ' this takes the number for how many times to loop
Dim strQueryName As String ' this is for the sql to find lowest rack number
Dim P As Integer 'this value is the prod number
Dim x As Integer 'value from lowestrackSQL
varNumber = Me.Quantity 'box from form me means this form
prodnumber = Me.ProdNo 'box from form
strQueryName = "SQLToFindLowestRackNumber" 'this will be used to execute the query
strSQL = CurrentDb.QueryDefs(strQueryName).sql ' this stores the sql but does not run it
Forms!form3!txtPrint = strResult
'Stop
For I = 1 To varNumber ' uses the quntity value to count how many times to loop
x = DLookup("locationrack", strQueryName) 'puts value of query into value x
prod# = prodnumber
'below puts into imediate view box
Debug.Print "Line number = " & I; "; Rack Location = " & x; "; Product Number = " & prod#; ";"
'below puts it into form3 text box
strResult = strResult & " Line Number = " & I & " Rack Location = " & x & " Product Numner = " & prod# & vbCrLf & ""
Forms!form3!Text5 = strResult
'below executes the SQL
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE [Location] SET [Location].ID = 0 WHERE [Location].RackID =" & x
DoCmd.SetWarnings True
Next I
End Sub
했던 것을 나는 코드를 첨부 다시 루프.
strResult 루프 (내가 추측하고있어 그 모듈/클래스 레벨에서) 내에서 선언되지 않습니다. vba 범위 지정 규칙이 ... 다른 경우에도 마찬가지입니다. 일단 변수가 선언되면 루프 일지라도 다시 초기화되지 않습니다. 루프에서 선언 된 또 다른 이상한 사실은 동일한 메소드에서 루프 뒤에 사용될 수 있습니다. 아마도 vba 프로그래머가 모든 것을 맨 위에 선언하는 경향이 있습니다. –
필자는 파일의 최상위를 가리키는'Option Compare Database'와'Option Explicit'의 부족과 'Dim P As Integer'의 선언을 통해 알 수 있듯이, 이것이 전혀 선언되지 않았다고 생각합니다. 값은 뚜껑 넘버 '이며, 나중에 선언없이'prodnumber'를 사용합니다. 어쨌든, 내가 제안한 변경 사항은 서브 옵티멀로 – Ghost
아 나는 그것을 놓친 경우 작동하도록해야합니다. –