Hi,
I have a form that performs searches and allows the user to append the record being viewed by pressing a command button.
I have 2 tables:
1, ma_enq with fields A1, A2, A3, A4 and name.
2, ma_dbo_uk with fields PRMF, Strd, Str, Locdd, Locd, PTN, and CTN.
The field PRMF is split by semicoloms "'" and a field SubString is created which holds the splitted fields as seperate records.
I want to be able to append more than one field into another divided by commas "," so it will look like format:
A1 A2
PRMF(SubString) Locdd
Strd Locd
Str
A3 A4
PTN Postcode
CNT
I want the apend query to do a conditional append for fields A1,A2,A3 that are going to hold more than one field if neccesary. If the field Strd is not empty add a comma before it "," and after it if Str is not empty, but if they are empty exclude the comma so:
SubString Strd Str
whsmith Pent Park Gladstone Road
A1
Whsmith, Pent Park, Gladstone Road
I want to do the same for the other fields like A2 and A3 that can hold more than one field.
At present my search query looks like:
SELECT I1.ID, I1.postcode, Mid$(";" & I1.PRMF & ";", S1.num + 1 , S2.num - S1.num - 1) AS [SubString], I1.STR, I1.CNT
FROM ma_dbo_uk AS I1, integers AS S1, integers AS S2
WHERE I1.postcode Like [Enter Postcode:] AND
Mid$(";" & I1.PRMF & ";" ,S1.num , 1 ) = ';'
and Mid$(";" & I1.PRMF & ";" ,S2.num , 1 ) = ';'
and S1.num+1 < S2.num
and instr(1,Mid$(";" & I1.PRMF & ";", S1.num + 1 , S2.num - S1.num - 1),";")=0;
and my append query like:
Private Sub Command18_Click()
Dim strSQL As String
strSQL = "INSERT INTO ma_enq ( A4, A1, A2, A3 ) " & _
"SELECT I1.postcode, Mid$(';' & I1.PRMF & ';',S1.num+1,S2.num-S1.num-1) AS SubString, I1.STR, I1.CNT " & _
"FROM ma_dbo_uk AS I1, integers AS S1, integers AS S2 " & _
"WHERE (((Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1))=[Forms]![Ma_search2]![PRMF_a1]) AND ((Mid$(';' & [I1].[PRMF] & ';',[S1].[num],1))=';') AND ((Mid$(';' & [I1].[PRMF] & ';',[S2].[num],1))=';') AND (([S1].[num]+1)<[S2].[num]) AND ((InStr(1,Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1),';'))=0));"
DoCmd.RunSQL strSQL
End Sub
Hope this makes senes if not i would be happy to explain further, thanks in advance.
M-.
I have a form that performs searches and allows the user to append the record being viewed by pressing a command button.
I have 2 tables:
1, ma_enq with fields A1, A2, A3, A4 and name.
2, ma_dbo_uk with fields PRMF, Strd, Str, Locdd, Locd, PTN, and CTN.
The field PRMF is split by semicoloms "'" and a field SubString is created which holds the splitted fields as seperate records.
I want to be able to append more than one field into another divided by commas "," so it will look like format:
A1 A2
PRMF(SubString) Locdd
Strd Locd
Str
A3 A4
PTN Postcode
CNT
I want the apend query to do a conditional append for fields A1,A2,A3 that are going to hold more than one field if neccesary. If the field Strd is not empty add a comma before it "," and after it if Str is not empty, but if they are empty exclude the comma so:
SubString Strd Str
whsmith Pent Park Gladstone Road
A1
Whsmith, Pent Park, Gladstone Road
I want to do the same for the other fields like A2 and A3 that can hold more than one field.
At present my search query looks like:
SELECT I1.ID, I1.postcode, Mid$(";" & I1.PRMF & ";", S1.num + 1 , S2.num - S1.num - 1) AS [SubString], I1.STR, I1.CNT
FROM ma_dbo_uk AS I1, integers AS S1, integers AS S2
WHERE I1.postcode Like [Enter Postcode:] AND
Mid$(";" & I1.PRMF & ";" ,S1.num , 1 ) = ';'
and Mid$(";" & I1.PRMF & ";" ,S2.num , 1 ) = ';'
and S1.num+1 < S2.num
and instr(1,Mid$(";" & I1.PRMF & ";", S1.num + 1 , S2.num - S1.num - 1),";")=0;
and my append query like:
Private Sub Command18_Click()
Dim strSQL As String
strSQL = "INSERT INTO ma_enq ( A4, A1, A2, A3 ) " & _
"SELECT I1.postcode, Mid$(';' & I1.PRMF & ';',S1.num+1,S2.num-S1.num-1) AS SubString, I1.STR, I1.CNT " & _
"FROM ma_dbo_uk AS I1, integers AS S1, integers AS S2 " & _
"WHERE (((Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1))=[Forms]![Ma_search2]![PRMF_a1]) AND ((Mid$(';' & [I1].[PRMF] & ';',[S1].[num],1))=';') AND ((Mid$(';' & [I1].[PRMF] & ';',[S2].[num],1))=';') AND (([S1].[num]+1)<[S2].[num]) AND ((InStr(1,Mid$(';' & [I1].[PRMF] & ';',[S1].[num]+1,[S2].[num]-[S1].[num]-1),';'))=0));"
DoCmd.RunSQL strSQL
End Sub
Hope this makes senes if not i would be happy to explain further, thanks in advance.
M-.