Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining fields 3

Status
Not open for further replies.

hoofit

Technical User
Nov 20, 2005
343
US
I have the following code:

strSql = "Insert into tblImage (txtImageName, fileName) VALUES ('" & strFolder & "', '" & strFile & "')"

Here's the values:
txtImageName is a field
fileName is a field
strFolder is "c:\photo"
strFile is "pic1.bmp"

I need to combine the 2 outputs to read c:\photo\pic1.bmp. Can this be done in code?

Thank you
 
Hi Dhookum,
The 2 outputs need to be combined into one path in a 3rd field in tblImage.

Thank you
 
It seems sort of redundant to repeat the data in a third field, when you can simply build the path later by simply combining the two fields.
e.g.
Code:
txtImageName & "\" & fileName

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
VB's not my strongpoint. I've got an array of data that populates the table. After the table is populated, I can go back and see the various files and paths that were documented.I'd rather not have a 3rd field but I'm not sure how your thought fits in...could you elaborate? :}
 

could you elaborate?
Using a query, you would have something like this:
Code:
SELECT txtImageName & "\" & filename As FullPath
FROM tblImage

Randy
 
Let me look at this tonite - don't want to keep anyone hanging and I will post tomorrow.

hoof
 
hoofit . . .

Via your post origination your ging to change [blue]txtImageName, fileName[/blue] to [blue]strFolder, strFile[/blue] for every record. This is because there's no [blue]where clause[/blue] to restrict the append. I'm looking & thinking you need an [blue]Update Query[/blue] to make the change. Something in the order of:
Code:
[blue]UPDATE tblImage  
Set [[purple][b]3rd FieldName[/b][/purple]] = [txtImageName] & "/" & [fileName] & ";"[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi guys,
Here's more of the code...

Private Sub cmdFolder_Click()
Dim recordID As Long
Dim strSql As String
Dim strFolder As String
Dim pathAndFile As String
Dim aImages() As String
Dim i As Integer
If Me.NewRecord Then Me.Dirty = False
'recordID = Me.ID

strFolder = BrowseFolder
aImages = getFiles(strFolder)

For i = LBound(aImages) To UBound(aImages)
If isValidImage(getExtension(aImages(i))) Then
If Not Right(strFolder, 1) = "\" Then strFolder = strFolder & "\"

'modify table name here
'strSql = "Insert into tblPics (folderPath, fileName, ParentID) VALUES ('" & strFolder & "', '" & aImages(i) & "'," & recordID & ")"
'strSql = "Insert into tblImageNames (folderPath, fileName) VALUES ('" & strFolder & "', '" & aImages(i) & "')" '& "'," & recordID & ")"

strSql = "Insert into tblImage (txtImageName, fileName) VALUES ('" & strFolder & "', '" & aImages(i) & "')"



Debug.Print strSql
CurrentDb.Execute strSql
End If
Next i


'subFrmCtlPics.Form.Requery
'Me.Parent.subFrmCtlPics.Requery
End Sub

I received errors on both the 'SELECT' word and the 'UPDATE' word. The code cycles thru a folder, identifies valid files and produces an array of info that is written to a table.

hoof
 
I pulled it out. It was just after the 'strsql' line. I'm not clearI need to credit MajP for some demo code as part of this project. I should just post the entire db. It may give a clear picture of what I'm attempting....votes?
 
My vote is to do your best to explain your current situation and requirements. We shouldn't have to play "20 questions" to get to your actual needs and determine what you current setup is.

Duane
Hook'D on Access
MS Access MVP
 
I worked thru this and ended up in a query with

Path: [folderPath] & [filename] thus resolving this
 
AceMan1
Ran your suggestion smoothly - thank you kindly. I left out the semi colon at the end.

hoof
 
I'm still having a dilemma. In this code, my attention is on folderpath. The folderpath in a table represents a combination of the other 2 fields.

'strSql = "Insert into tblImageNames (FolderPath, strFolder, aImages) VALUES ('" & FolderPath & "', strFolder & "', '" & aImages(i) & "')"


Thus I need the code to read something like this;
'strSql = "Insert into tblImageNames (FolderPath, strFolder, aImages) VALUES ('" [strFolder]& [aImages],& strFolder & aImages"')"

I'm not sure that this is any clearer.

hoof
 
I don't quite understand. You "something like this" has 3 fields to insert into and only 1 comma or 2 values. Can we assume that each item in the VALUES is a string variable?

Duane
Hook'D on Access
MS Access MVP
 
You wanted this ?
Code:
strSql = "Insert into tblImageNames (FolderPath, strFolder, aImages) VALUES ('" & strFolder & aImages(i) & "', strFolder & "', '" & aImages(i) & "')"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have a tough time explaining, I apologize. Let me back up. I have a table with 3 fields -

path
strFolder
aImages

The value of strFolder is c:\
The value of aImages is test.bmp

What I need is to have the value of path c:\test.bmp

My question is can this be done as I am currently attempting with code as above. In other words, path would be written at the time the other 2 are via code

hoof
 
I believe PH provided the appropriate answer/code.

At least 3 of us in this thread have questioned why you need to store the combined value when you already have the separate values stored in the same record.

Duane
Hook'D on Access
MS Access MVP
 
PHV,
Thank you for the response. Result indicates a syntax error (missing operator) 'strfolder &" when I run it. Could you recheck

hoof
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top