JustJerry
07-21-2006, 08:54 AM
Good Morning Folks,
Messing around with another program, and I seem to have hit a snag for some reason I can't figure out. Here is my code that I'm trying to work with.
Private Sub OpnTwrInfo_Click()
On Error GoTo Err_OpnTwrInfo_Click
'Set values for variables
Dim stDocName As String
Dim stLinkCriteria As String
Dim cmainid As Integer
cmainid = Me.MainID.Value 'assign current form value for MainID
'Check to see if existing record exists in Table tblTowerInfo for value MainID. If no record exist
'then set new records MainID value to equal that of MainID of form frmInfo. If record does exist
'then open up that record
If IsNull(DLookup("[MainID]", "tblTowerInfo", "[MainID]=" & Me.MainID.Value)) Then
DoCmd.OpenForm "frmTwrInfo"
[Forms]![frmTwrInfo].Form!MainID.Value = cmainid
Exit Sub
Else
stDocName = "frmTwrInfo"
stLinkCriteria = "[MainID]=" & Me![MainID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
End If
Exit_OpnTwrInfo_Click:
Exit Sub
Err_OpnTwrInfo_Click:
MsgBox Err.Description
Resume Exit_OpnTwrInfo_Click
End Sub
Here is what happens.
I have a table named tblMain with an autonumber field called MainID. This is my primary key as well. I have a form called frmInfo based on this table.
From frmInfo, I am trying to open up another form based on a seperate table (tblTowerInfo). In this table I have a Number field named MainID. The form I am opening is called frmTwrInfo.
SO, I am on the form frmInfo, and I click the command button to open up frmTwrInfo the very first time and the code works. It sees that there is no record in tblTowerInfo, opens up the form frmTwrInfo and assigns the value of frmInfo's MainID to the MainID field on frmTwrInfo.
I close everythign down. Now I go back to frmInfo and see if it will open up frmTwrInfo to the correct record. It doesn't. It shows in the Navigation bar that the opened form is 'filtered', for example MainID=1, yet there is nothing showing on the form that I entered the first time.
I look in both tables, both tables have the fields MainID with exact values. So why won't my second form open with the right record showing? What am I missing.
I set up a relationship between these tables via MainID. I tried with and without the relationship existing, and this didn't make any difference.
Thanks for any help
Jerry
Messing around with another program, and I seem to have hit a snag for some reason I can't figure out. Here is my code that I'm trying to work with.
Private Sub OpnTwrInfo_Click()
On Error GoTo Err_OpnTwrInfo_Click
'Set values for variables
Dim stDocName As String
Dim stLinkCriteria As String
Dim cmainid As Integer
cmainid = Me.MainID.Value 'assign current form value for MainID
'Check to see if existing record exists in Table tblTowerInfo for value MainID. If no record exist
'then set new records MainID value to equal that of MainID of form frmInfo. If record does exist
'then open up that record
If IsNull(DLookup("[MainID]", "tblTowerInfo", "[MainID]=" & Me.MainID.Value)) Then
DoCmd.OpenForm "frmTwrInfo"
[Forms]![frmTwrInfo].Form!MainID.Value = cmainid
Exit Sub
Else
stDocName = "frmTwrInfo"
stLinkCriteria = "[MainID]=" & Me![MainID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
End If
Exit_OpnTwrInfo_Click:
Exit Sub
Err_OpnTwrInfo_Click:
MsgBox Err.Description
Resume Exit_OpnTwrInfo_Click
End Sub
Here is what happens.
I have a table named tblMain with an autonumber field called MainID. This is my primary key as well. I have a form called frmInfo based on this table.
From frmInfo, I am trying to open up another form based on a seperate table (tblTowerInfo). In this table I have a Number field named MainID. The form I am opening is called frmTwrInfo.
SO, I am on the form frmInfo, and I click the command button to open up frmTwrInfo the very first time and the code works. It sees that there is no record in tblTowerInfo, opens up the form frmTwrInfo and assigns the value of frmInfo's MainID to the MainID field on frmTwrInfo.
I close everythign down. Now I go back to frmInfo and see if it will open up frmTwrInfo to the correct record. It doesn't. It shows in the Navigation bar that the opened form is 'filtered', for example MainID=1, yet there is nothing showing on the form that I entered the first time.
I look in both tables, both tables have the fields MainID with exact values. So why won't my second form open with the right record showing? What am I missing.
I set up a relationship between these tables via MainID. I tried with and without the relationship existing, and this didn't make any difference.
Thanks for any help
Jerry