I am working through "MS Access 2000 VBA Fundamentals" by Callahan and have hit a road block. So, I'm hoping someone can help me out.
The database I've built to test this function has two tables:
tblSubscribers: SubscriberID(PK), LastName
tblPayments: PaymentID(PK), SubscriberID(FK), PaymentDate
I have two forms – one bound to each table:
frmSubscribers and frmEnterPayments
frmSubscribers has a command button that opens frmEnterPayments.
When frmEnterPayments opens, it has the SubscriberID already filled via the following code in the On Open event.
Private Sub Form_Open(Cancel As Integer)
' Set the default to the current subscriber.
If IsOpen("frmSubscribers") Then
SubscriberID.DefaultValue = Forms!frmSubscribers!SubscriberID
End If
End Sub
OnOpen function is in a misc. module:
Public Function IsOpen(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view.
Const conDesignView = 0
Const conObjStateClosed = 0
IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> _
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If
End Function
Here's my problem - The frmEnterPayments form does not open correctly if I set the SubscriberID field type to text. In my real application, where I want to use this, my primary key is a text field. If I change it to autonumber, it works fine. Can someone help me out?
Thanks,
Mike
The database I've built to test this function has two tables:
tblSubscribers: SubscriberID(PK), LastName
tblPayments: PaymentID(PK), SubscriberID(FK), PaymentDate
I have two forms – one bound to each table:
frmSubscribers and frmEnterPayments
frmSubscribers has a command button that opens frmEnterPayments.
When frmEnterPayments opens, it has the SubscriberID already filled via the following code in the On Open event.
Private Sub Form_Open(Cancel As Integer)
' Set the default to the current subscriber.
If IsOpen("frmSubscribers") Then
SubscriberID.DefaultValue = Forms!frmSubscribers!SubscriberID
End If
End Sub
OnOpen function is in a misc. module:
Public Function IsOpen(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view.
Const conDesignView = 0
Const conObjStateClosed = 0
IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> _
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If
End Function
Here's my problem - The frmEnterPayments form does not open correctly if I set the SubscriberID field type to text. In my real application, where I want to use this, my primary key is a text field. If I change it to autonumber, it works fine. Can someone help me out?
Thanks,
Mike