I had gotten my database working the way I wanted, so I cleared out all the data I used to test the database. I compacted the database to get all the autonumbers to reset. Now I am getting a null error in 2 fields on a form. The fields are supposed to be populated by the following code:
Dim stDocName As String
Dim stLinkCriteria As String
Dim Counter As String
stDocName = "frmCane2"
stLinkCriteria = "[CanisterID]=" & Me![cboCanister]
DoCmd.OpenForm stDocName
DoCmd.GoToRecord , , acLast
Counter = Forms![frmCane2]![SampleID] + 1
DoCmd.Close acForm, "frmCane2", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms![frmCane2]![CanisterID] = Forms![frmCanisterSelect]![cboCanister]
Forms![frmCane2]![SampleID] = Counter
DoCmd.Close acForm, "frmCanisterSelect", acSaveNo
The code is on the On Click Event for the button on frmCanisterSelect which opens frmCane2. This code is supposed to get the CanisterID from a selection made on the frmCanisterSelect, and then get the next number for a SampleID from tblCane. Niether CanisterId or SampleID are getting populated on frmCane2. I assume it is because there are no records in tblCane, so it can't find the last record, but I don't know how to fix it without putting in a bogus record.
Any help would be appreciated,
Dim stDocName As String
Dim stLinkCriteria As String
Dim Counter As String
stDocName = "frmCane2"
stLinkCriteria = "[CanisterID]=" & Me![cboCanister]
DoCmd.OpenForm stDocName
DoCmd.GoToRecord , , acLast
Counter = Forms![frmCane2]![SampleID] + 1
DoCmd.Close acForm, "frmCane2", acSaveNo
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms![frmCane2]![CanisterID] = Forms![frmCanisterSelect]![cboCanister]
Forms![frmCane2]![SampleID] = Counter
DoCmd.Close acForm, "frmCanisterSelect", acSaveNo
The code is on the On Click Event for the button on frmCanisterSelect which opens frmCane2. This code is supposed to get the CanisterID from a selection made on the frmCanisterSelect, and then get the next number for a SampleID from tblCane. Niether CanisterId or SampleID are getting populated on frmCane2. I assume it is because there are no records in tblCane, so it can't find the last record, but I don't know how to fix it without putting in a bogus record.
Any help would be appreciated,