我有一些代码填充了一个名为text5 Forms!Form3!text5
. 但是每次我单击更新此文本框的按钮时,它都会刷新它。
我希望文本保持固定,并在每次单击按钮时添加新数据。我已经附上了我到目前为止所做的代码
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
被传递到文本框,我只想继续将值添加到文本框,即使在我再次重新启动循环后也是如此。