Add Fixed Value to Field

fenhow

Registered User.
Local time
Today, 09:09
Joined
Jul 21, 2004
Messages
599
I have a textbox that is populated with a value as a result of a button, that function works fine.

What I am trying to do is have some information fixed and the result of the button added to the end of it.

For an example, When I click a button the word mydoc.txt is placed in the textbox.

What I would like is C:\Folder\ waiting or default and when the button is clicked the result would be C:\Folder\mydoc.txt

I hope I explained that to make sense.. Can someone please tell me how to accomplish this?

Thanks.

Fen
 
How do you populate the textbox? You should be able to concatenate the fixed string at the beginning of it.
 
Enter the Control Source of the textbox as:

="C:\Folder\" & ButtonResult
 
I tried this and i get an error "You cannot assign a value to this object" when i run it?

="C:\Folder\" & [CRFileName]
 
Paul, the textbox is populated after a selection of a file is made using this code. The tbFile is the name of my textbox.

Fen

Private Sub Label510_Click()
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant

Me.tbHidden.SetFocus

' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _
' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*"
strFilter = "All Files (*.*)" & vbNullChar & "*.*"

lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly

varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngFlags, _
strInitialDir:="", _
strDialogTitle:="Find File (Select The File And Click The Open Button)")
'remove the strInitialDir:="C:\Windows\", _ line if you do not want the Browser to open at a specific location

If IsNull(varFileName) Or varFileName = "" Then
Debug.Print "User pressed 'Cancel'."
Beep
MsgBox "File selection was canceled.", vbInformation
Exit Sub
Else
'Debug.Print varFileName
tbFile = varFileName
End If

Call ParseFileName

Exit_bBrowse_Click:
Exit Sub

Err_bBrowse_Click:
MsgBox err.Number & " - " & err.Description
Resume Exit_bBrowse_Click
End Sub
 
I tried this and i get an error "You cannot assign a value to this object" when i run it?

="C:\Folder\" & [CRFileName]

It appears you are trying to set the value of the textbox using VBA.
You cannot set a value for a bound control.

You simply need to enter the expression as the Control Source property of the box. This will make it bound to the expression and its value will automatically follow the value of [CRFileName] with the path prepended.
 
Thanks, can you show me an example, i dont quite follow you.. but i am close.
 
Ok, another approach, i have three bound textboxes 1, 2, 3 is there anyway i can merge 1 & 2 to write in 3?

Thanks..

Fen
 
Much the same either way.

Right click the box you want to show the final result and select Properties.
Control Source is the top Property under the Data tab.

Type the expression in there. It probably currently has CRFileName

To concatenate the values from two boxes:

=[box1] & [box2]

If you want to change the box contents by using VBA you must leave Control Source blank.
 
Last edited:
Ok but i really need the result to be written to the table.

So Box 1 is CRFileName (bound to the table as CRFileName) which is added when the user selects the file
Box 2 is CRPath (Unbound) the path C:\File\ which is fixed
Box 3 is CRLink(Bound to the table as CRLink)the result of Box 1 and Box 2

Thanks.

Can the result Box 3 be saved to the table.
 
Use VB to update the table.

Dim strCommand As String

strCommand = "Update [TableName] SET TableName.FieldName = "
strCommand = strCommand & "'" & Me!textboxname & "' WHERE ...some condition... "

CurrentDb.Execute strCommand
 
Last edited:

Users who are viewing this thread

Back
Top Bottom