Hi,
I have a solution that works for me and was limited to 5 fields but can increase of required.
I created a table for selection of fields
FieldDesc
FieldName
FieldType
FieldSelectNo
I then Created a popup where they place a 1 to 5 in the FieldSelectNo
Using the dlookup on the FieldSelectno I can get the FieldType.
With this I create a table with right data types but always called the field names Blank1 to Blank5,
I used the SELECT function to build the table if they needed less then 5
vFt1 = DLookup("[FieldType]", "ReportSelect", "[FieldSelectNo] = 1")
vFt2 = DLookup("[FieldType]", "ReportSelect", "[FieldSelectNo] = 2")
Vft3 = DLookup("[FieldType]", "ReportSelect", "[FieldSelectNo] = 3")
vFt4 = DLookup("[FieldType]", "ReportSelect", "[FieldSelectNo] = 4")
vFt5 = DLookup("[FieldType]", "ReportSelect", "[FieldSelectNo] = 5")
'******************************** Create new table '******************************************************************
On Error Resume Next
DoCmd.DeleteObject acQuery, "AAAANew"
'**********************************************************
Dim strSQL As String
Set db = DBEngine(0)(0)
strSQL = "CREATE TABLE [AAAANew] (Surname Text, Given Text, Volunteer Text, Blank1 " & vFt1 & ",Blank2 " & vFt2 & ", Blank3 " & Vft3 & ", Blank4 " & vFt4 & ", Blank5 " & vFt5 & ");"
db.Execute strSQL
Set db = Nothing
Then I created a INSERT query.
'**********************************************************
vFn1 = DLookup("[FieldName]", "ReportSelect", "[FieldSelectNo] = 1")
vFn2 = DLookup("[FieldName]", "ReportSelect", "[FieldSelectNo] = 2")
vFn3 = DLookup("[FieldName]", "ReportSelect", "[FieldSelectNo] = 3")
vFn4 = DLookup("[FieldName]", "ReportSelect", "[FieldSelectNo] = 4")
vFn5 = DLookup("[FieldName]", "ReportSelect", "[FieldSelectNo] = 5")
Set db = CurrentDb
Dim qryDef As DAO.QueryDef
Dim selectSQL As String
On Error Resume Next
DoCmd.DeleteObject acQuery, "Q_AAAANew"
'**********************************************************
selectSQL = "INSERT INTO AAAANew ( Surname, Given, Blank1, Blank2, Blank3, Blank4, Blank5 ) " & _
"SELECT Volunteers.Surname, Volunteers.Given, Volunteers.Vol, Volunteers." & vFn1 & ", Volunteers." & vFn2 & ", Volunteers.DatewExp, Volunteers.Mobile " & _
"FROM Volunteers;"
The only issue is that the report field widths are all the same, in my case it was not an issue as the fields were either a data or yes/no.
Hope someone can expand on this as I am a very much a 'cut and paste' programmer.
Regards
Peter