SteveL13
asked on
How create table via VBA code that only includes fields with values from another table
I have a table named tblMatlSpecsChemical. Some of the fields have a value in them and some of them don't have a value. What I want to do, via VBA code, is create a 2nd temporary table that only contains the fields from the 1st table that have values in them.
So if for example table one has a field named C_MIN and that field has a value in it, then include the field name and the field value in the temporary table. But if another field for example named Mn_MIN has no value in the 1st table, then do not include the field name or field value in the temporary table.
I've tried variations of this code but it isn't working so I'm sure I've got something wrong.
So if for example table one has a field named C_MIN and that field has a value in it, then include the field name and the field value in the temporary table. But if another field for example named Mn_MIN has no value in the 1st table, then do not include the field name or field value in the temporary table.
I've tried variations of this code but it isn't working so I'm sure I've got something wrong.
Dim RS As DAO.Recordset
Dim rst As DAO.Recordset
Set rst = Nothing
Set RS = CurrentDb.OpenRecordset("tblSpecReportChemical")
RS.AddNew
If Me!subfrmMatlSpecsChemical.Form!txtC_MIN > 0 Then
RS!C_MIN = Me!subfrmMatlSpecsChemical.Form!txtC_MIN
End If
If Forms!subfrmMatlSpecsChemical.Form.txtMN_MIN > 0 Then
RS!MN_MIN = Forms!subfrmMatlSpecsChemical.Form.txtMN_MIN
End If
RS.Update
MsgBox "The spec data has been entered into the spec report data table."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Does this table only contain 1 record, ...or are we talking about multiple records, ...all with Fieldx empty?
In a nutshell, I am with Pat...
So while it is certainly possible to loop the fields and collect the name of any non empty field(s), ...
then build an SQL statement in code, ...to only include the non empty fields, ...I don't see the point either...
As always, ...it is always helpful to know the ultimate need here, ...in case there is an easier/alternate way to do get what you need...
Outstanding questions:
Whats the reason for the temp table?
Why is it imperative that the blank fields be removed?
JeffCoachman
In a nutshell, I am with Pat...
So while it is certainly possible to loop the fields and collect the name of any non empty field(s), ...
then build an SQL statement in code, ...to only include the non empty fields, ...I don't see the point either...
As always, ...it is always helpful to know the ultimate need here, ...in case there is an easier/alternate way to do get what you need...
Outstanding questions:
Whats the reason for the temp table?
Why is it imperative that the blank fields be removed?
JeffCoachman
ASKER