B
BruceM
In advance, sorry this is so long. I cannot think of a way to compress it.
I have a vendor database. There is a main Vendors table, and a related
PhoneNumber table (since there could be several phone numbers).
There are two forms. One lists all vendors; the other is a subset of
vendors. The forms display significantly different information, so there
are two separate forms (frmMain and frmLimited). I want it to be possible
to add or edit a phone number from either form by calling the same pop-up
form (unless there are specific reasons why I shouldn't do it that way).
The pop-up form is bond to the PhoneNumber table. For phone number display
on frmMain or frmLimited I am using a list box (lstPhone). It's row source
is set in the Current event event of frmMain or frmLimited:
Me.lstPhone = -1
Me.lstPhone.RowSource = "SELECT Phone FROM tblPhone " & _
"WHERE VendorID = " & Me.VendorID & " ORDER BY MainPhone"
Me.lstPhone.Requery
This works as intended.
To change a number I use the Click event of an unassociated label on frmMain
or frmLimited to open the pop-up form frmAddPhone (bound to the PhoneNumber
table):
Dim strArgs As String, strWhere As String
strArgs = Me.VendorID & "|" & Me.VendorName & "|" & Me.Form.Name
strWhere = "VendorID = " & Me.VendorID
Me.Dirty = False
DoCmd.OpenForm "frmAddPhone", , , strWhere, , acDialog, strArgs
So far so good. Now I click the New button on frmAddPhone, which takes me
to a new record. I add the phone number and click an Add button. This is
the awkward code I need to use (explanation of fVendID and fFormName to
follow):
Dim lngID As Long
Dim strRow As String
If Me.NewRecord Then
lngID = fVendID
Me.VendorID = lngID
strRow = "SELECT Phone FROM tblPhone WHERE VendorID = " & _
lngID & " ORDER BY MainPhone"
If fFormName = "frmMain" Then
With Forms!frmMain
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
ElseIf fFormName = "frmLimited" Then
With Forms!frmLimited
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
End If
End If
fFormName is a function in the frmAddPhone module (error handling omitted
for this posting):
Public Function fFormName()
fFormName = Split(Me.OpenArgs, "|")(2)
End Function
fVendID is similar, but returns a number.
fFormName gives me a value I can check in the Add button code above.
However, it seems I should be able to do:
If Me.NewRecord Then
lngID = fVendID
Me.VendorID = lngID
strRow = "SELECT Phone FROM tblPhone WHERE VendorID = " & _
lngID & " ORDER BY MainPhone"
If fFormName = "frmMain" Then
With Forms!fFormName
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
End If
End If
I have tried:
Public Function fFormName() as Variant
and also I tried converting the value to a variant in the Add button code.
The frustration is that I can see (when I step through the code) the value
frmMain or frmApproved that is returned by fFormName, but I cannot use the
value in the With statement.
There is similar code in the click event of an unassociated label on
frmAddPhone to delete a phone number and reset the list box:
Dim strRow As String
Dim varForm As Variant
strRow = "SELECT Phone FROM tblPhone WHERE VendorID = " & _
fVendID & " ORDER BY MainPhone"
Me.txtCounter = ""
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDelete
If Me.CurrentRecord > Me.RecordsetClone.RecordCount Then
Me.Recordset.MoveLast
End If
varForm = fFormName
If fFormName = "frmMain" Then
With Forms!frmMain
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
ElseIf fFormName = "frmLimited" Then
With Forms!frmLimited
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
End If
In a possibly related matter, when I run the Delete code the list box view
refreshes. That is, if there are two phone numbers, the list box (which is
one row high) shows up and down arrows. After deleting a phone number the
list box shows no arrows (just one number left). However, when I *add* a
phone number, the list box view does not refresh. If it had one number it
still has one number, and there are no up and down arrows. If I move to
another main form record and back, the list box contains the information it
should, and the up and down arrows appear as they should. I can't figure
out why the Delete code refreshes the list box and the Add code does not. I
have tried refreshing and repainting the form, but it makes no difference.
I have a vendor database. There is a main Vendors table, and a related
PhoneNumber table (since there could be several phone numbers).
There are two forms. One lists all vendors; the other is a subset of
vendors. The forms display significantly different information, so there
are two separate forms (frmMain and frmLimited). I want it to be possible
to add or edit a phone number from either form by calling the same pop-up
form (unless there are specific reasons why I shouldn't do it that way).
The pop-up form is bond to the PhoneNumber table. For phone number display
on frmMain or frmLimited I am using a list box (lstPhone). It's row source
is set in the Current event event of frmMain or frmLimited:
Me.lstPhone = -1
Me.lstPhone.RowSource = "SELECT Phone FROM tblPhone " & _
"WHERE VendorID = " & Me.VendorID & " ORDER BY MainPhone"
Me.lstPhone.Requery
This works as intended.
To change a number I use the Click event of an unassociated label on frmMain
or frmLimited to open the pop-up form frmAddPhone (bound to the PhoneNumber
table):
Dim strArgs As String, strWhere As String
strArgs = Me.VendorID & "|" & Me.VendorName & "|" & Me.Form.Name
strWhere = "VendorID = " & Me.VendorID
Me.Dirty = False
DoCmd.OpenForm "frmAddPhone", , , strWhere, , acDialog, strArgs
So far so good. Now I click the New button on frmAddPhone, which takes me
to a new record. I add the phone number and click an Add button. This is
the awkward code I need to use (explanation of fVendID and fFormName to
follow):
Dim lngID As Long
Dim strRow As String
If Me.NewRecord Then
lngID = fVendID
Me.VendorID = lngID
strRow = "SELECT Phone FROM tblPhone WHERE VendorID = " & _
lngID & " ORDER BY MainPhone"
If fFormName = "frmMain" Then
With Forms!frmMain
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
ElseIf fFormName = "frmLimited" Then
With Forms!frmLimited
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
End If
End If
fFormName is a function in the frmAddPhone module (error handling omitted
for this posting):
Public Function fFormName()
fFormName = Split(Me.OpenArgs, "|")(2)
End Function
fVendID is similar, but returns a number.
fFormName gives me a value I can check in the Add button code above.
However, it seems I should be able to do:
If Me.NewRecord Then
lngID = fVendID
Me.VendorID = lngID
strRow = "SELECT Phone FROM tblPhone WHERE VendorID = " & _
lngID & " ORDER BY MainPhone"
If fFormName = "frmMain" Then
With Forms!fFormName
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
End If
End If
I have tried:
Public Function fFormName() as Variant
and also I tried converting the value to a variant in the Add button code.
The frustration is that I can see (when I step through the code) the value
frmMain or frmApproved that is returned by fFormName, but I cannot use the
value in the With statement.
There is similar code in the click event of an unassociated label on
frmAddPhone to delete a phone number and reset the list box:
Dim strRow As String
Dim varForm As Variant
strRow = "SELECT Phone FROM tblPhone WHERE VendorID = " & _
fVendID & " ORDER BY MainPhone"
Me.txtCounter = ""
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDelete
If Me.CurrentRecord > Me.RecordsetClone.RecordCount Then
Me.Recordset.MoveLast
End If
varForm = fFormName
If fFormName = "frmMain" Then
With Forms!frmMain
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
ElseIf fFormName = "frmLimited" Then
With Forms!frmLimited
!lstPhone = -1
!lstPhone.RowSource = strRow
!lstPhone.Requery
!txtVendorName.SetFocus
End With
End If
In a possibly related matter, when I run the Delete code the list box view
refreshes. That is, if there are two phone numbers, the list box (which is
one row high) shows up and down arrows. After deleting a phone number the
list box shows no arrows (just one number left). However, when I *add* a
phone number, the list box view does not refresh. If it had one number it
still has one number, and there are no up and down arrows. If I move to
another main form record and back, the list box contains the information it
should, and the up and down arrows appear as they should. I can't figure
out why the Delete code refreshes the list box and the Add code does not. I
have tried refreshing and repainting the form, but it makes no difference.