Hi All
I am having an issue with DLOOKUP in some of my code.
In short I have an unbound form that once a save button is clicked the text boxes and combo boxes in the unbound form dump the data into a table.
The problem I am having is that I need to perform a calculation on some of the data using the DLOOKUP function which keeps returning a null value.
This is the code I have scripted so far. The Year field in the table is a number and the state field is text.
I am having an issue with DLOOKUP in some of my code.
In short I have an unbound form that once a save button is clicked the text boxes and combo boxes in the unbound form dump the data into a table.
The problem I am having is that I need to perform a calculation on some of the data using the DLOOKUP function which keeps returning a null value.
This is the code I have scripted so far. The Year field in the table is a number and the state field is text.
Code:
Private Sub btnSaveElec_Click()
'Saves data from unbound text boxes in the Electricity tab to table tblElectricityData
Dim db As Database
Dim rst As Recordset
Dim SaveSQL As String
newFlag = Me!chkNewElec
If newFlag = True Then
SaveSQL = "SELECT * FROM tblElectricityData"
Else
SaveSQL = "SELECT * FROM tblElectricityData " & _
"WHERE ID = " & Me!TxtIDElec
End If
Set rst = CurrentDb.OpenRecordset(SaveSQL)
If Me!chkNewElec = True Then
rst.AddNew
Else
rst.Edit
End If
rst!InvoiceNumber = Me!txtInvoiceNoElec
rst!Site = Me!txtBDElec
rst!State = Me!txtStateElec
rst!Year = Me!txtYearElec
rst!KiloWattHours = Me!txtkWhElec
rst!BaseBuilding = Me!ChkBBElec
rst!Share = Me!txtShareElec
rst!Scope2Emissions = Me!txtkWhElec * DLookup("Scope2EmissionFactor1", "tblStdEFElectricity", _
"EmissionFactorRegion='" & rst!State & " And " & "Year=" & rst!Year)
rst.Update
rst.Close
Set rst = Nothing
Me!chkNewElec = False
Me!frmsubElectricityData.Requery
Me!frmsubElectricityData.SetFocus
Me!btnAddNewElec.Enabled = True
Me!btnEditElec.Enabled = True
Me!btnCancelElec.Enabled = False
Me!btnSaveElec.Enabled = False
End Sub
[/CODE
I;m not sure what I am suppose to be doing with rst!Year and rst!State. DO they need to be wrapped in " or ' . ANy guidance around this would be great.
Cheers