Good Morning:
I am using the following code to add new records to a table that is on my Sub Form. Below is the code that I placed in my Before Update event on my Sub Form:
[code=vb]
Private Sub Form_BeforeUpda te(Cancel As Integer)
'When records are added it adds the coresponding LocationsID, YearID and Month IDs
'to the new record.
If Me.NewRecord Then
JtnLocationsID = Forms!Forecastf orm!cboLocation
YearID = Forms!Forecastf orm!CboYear
MonthID = Forms!Forecastf orm!CboMonth
End If
End Sub
[/code]
What I am finding is that the control on my form (cboLocation) is sometimes blank and that causes me to error out on adding new records (because it is a null value) even though I have other controls/combo boxes that are displaying what the LocationsID should be.
The LocationsID can be found in my following table:
Table Name :tblLocationsMM
Field Name = DivisionIDFK = Number
Field Name = WrkRegIDFK = Number
Field Name = CreditRegIDFK = Number
Field Name = LocationsID = AutoNumber
Like I mentioned, I am displaying the DivisionIDFK, WrkRegIDFK, CreditRegIDFK via three other controls on my form:
DivisionIDFK = cboDivision
WrkRegIDFK = cboWrkReg
CreditRegIDFK = cboCreditReg
My question is, instead of me referencing the control (cboLocation) on my form to get the LocationsID, is there a way that I code write the code to lookup the LocationsID based on my other controls on my form (cboDivision, cboWrkReg, cboCreditReg) that never blank out?
Any direction would be greatly appreciated
Thanks,
Keith.
I am using the following code to add new records to a table that is on my Sub Form. Below is the code that I placed in my Before Update event on my Sub Form:
[code=vb]
Private Sub Form_BeforeUpda te(Cancel As Integer)
'When records are added it adds the coresponding LocationsID, YearID and Month IDs
'to the new record.
If Me.NewRecord Then
JtnLocationsID = Forms!Forecastf orm!cboLocation
YearID = Forms!Forecastf orm!CboYear
MonthID = Forms!Forecastf orm!CboMonth
End If
End Sub
[/code]
What I am finding is that the control on my form (cboLocation) is sometimes blank and that causes me to error out on adding new records (because it is a null value) even though I have other controls/combo boxes that are displaying what the LocationsID should be.
The LocationsID can be found in my following table:
Table Name :tblLocationsMM
Field Name = DivisionIDFK = Number
Field Name = WrkRegIDFK = Number
Field Name = CreditRegIDFK = Number
Field Name = LocationsID = AutoNumber
Like I mentioned, I am displaying the DivisionIDFK, WrkRegIDFK, CreditRegIDFK via three other controls on my form:
DivisionIDFK = cboDivision
WrkRegIDFK = cboWrkReg
CreditRegIDFK = cboCreditReg
My question is, instead of me referencing the control (cboLocation) on my form to get the LocationsID, is there a way that I code write the code to lookup the LocationsID based on my other controls on my form (cboDivision, cboWrkReg, cboCreditReg) that never blank out?
Any direction would be greatly appreciated
Thanks,
Keith.
Comment