开发者

Error message when trying to open a Form in Access

开发者 https://www.devze.com 2023-03-05 01:23 出处:网络
When I try to open a form in Access I get an error message that says You entered the control name \'col1,\' which is already in use. The code where this error happens is at

When I try to open a form in Access I get an error message that says You entered the control name 'col1,' which is already in use. The code where this error happens is at Forms(frm)(i+16).Name="col" & Format(i, "0")below. What does this error mean? And how can i correct it?

Sub SetGridColumns(frm As String, FirstDay As Variant, LastDay As Variant)
Dim i As Integer
' Sets column headings for all shown dates in crosstab fsub
DoCmd.OpenForm frm, acDesign, , , , acHidden
For i = 0 To 7
    ' Avoid control name conflicts by renaming them to col1 ...
    ' The dirty constant 16 is the item number of the last non-column item.
    **Forms(frm)(i + 16).Name = "col" & Format(i, "0")**
Next i
For i = 0 To 7
    ' Now give the columns the right control name and control source
    Forms(frm)(i + 1开发者_如何学JAVA6).ControlSource = Format(FirstDay + i, "mm-dd")
    Forms(frm)(i + 16).Name = Format(FirstDay + i, "mm-dd")
Next i
DoCmd.Close acForm, frm, acSaveYes
End Sub


It means what it says. To find the control which is already named 'col1', before your first loop, output to debug all the names of your form's controls.


If you were running into errors then there may be some lingering control with the name col1, etc., although logically, they should have the name FirstDay + i + "mm-dd". So, as Joel suggests, you can manually check for and correct those controls, or you could put in a check before the rename:

If Forms(frm)(i + 16).Name <> "col" & Format(i, "0") Then
   Forms(frm)(i + 16).Name = "col" & Format(i, "0")
End If
0

精彩评论

暂无评论...
验证码 换一张
取 消