Frage

I have to do some changes to a program that runs on Access 2003.

I have a form where clicking on a certain button will change the text of a textbox depending on what is selected (image research). Originally, this textbox is linked to another hidden textbox that contain the original path for this image (the one in the database / unedited).

My problem consists of the following: when I want the textbox that is linked to the DB to change to match the other textbox (containing the newest path), and thus allowing Access to save the changes, it just doesn't work. The textbox linked to the DB just goes blank.

Here is the code I work with in VBA:

Public Sub SearchForImage(ByVal txtName As String, ByVal txtAuto As String)
    On Error Resume Next
    Dim B As String

    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .Show
        Me.Controls(txtName).SetFocus
        Me.Controls(txtName).Text = ""
        B = .SelectedItems(1)
    End With
    Me.Controls(txtAuto).SetFocus
    Me.Controls(txtAuto).Text = ""
    Me.Controls(txtAuto) = B
End Sub

This allows me to change the text (along with another bit of code that isn't liked to the problem [it just make the text go blank before inputting the new value]). "txtName" represents the diffrent textbox I send to the function (these are not linked to the database in any way), and "txtAuto" the textbox linked to the database with a source control.

Does anyone have an idea of why I can't change the value of this ? Is it because the textbox is linked with a source control ? Would it be better to directly save the content of 'B' in the database ?

War es hilfreich?

Lösung

I'm unsure how well I understand what you're trying to do. However, I think you should use those controls' .Value properties instead of .Text, and then you don't need to .SetFocus first.

'On Error Resume Next ' <-- avoid this whenever possible
Dim B As String
With Application.FileDialog(1) ' msoFileDialogOpen
    .AllowMultiSelect = False
    If .Show = True Then
        B = .SelectedItems(1)
        Me.Controls(txtName).Value = B
    End If
End With
Me.Controls(txtAuto).Value = B

That may not do exactly what you want. However, without On Error Resume Next active, at least it may give you and us a clearer understanding of the problem.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top