getting subform information

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hello. I have a mainform (Purchase Orders) and a subform
(zPurchaseOrderItems). I am using the code below to determine if the
items in the subform match the projectid of the default charge acct.
The msgboxes are used for when building the routine to see where it
goes. The first msgbox does show the appropriate projectid. But in
the ElseIf line I get the problem. It seems that the ElseIf is not
being looked at. Even if I hardcode the projectid into the line in
place of the sql_po_approved(0) it still skips over it. Is the
referencing of the subform correct? Is this the way to go about
getting the info?

Dim sql_po_approved As ADODB.Recordset
Dim sql_po As String
Set conn = New ADODB.Connection
conn.Open "Driver={SQL Server};Server=test-
mxsql-02;Database=MTXMain;User ID=sa;Password=h0rn3t;" 'need to change
the server back to MXSQL before production
sql_po = "SELECT ProjectID FROM ChargeAccounts WHERE ID =
dbo.POGetChargeAccountID(" & PONumber & ")"
Set sql_po_approved = New ADODB.Recordset
sql_po_approved.Open sql_po, conn, adOpenKeyset,
adLockReadOnly

MsgBox sql_po_approved(0)

If Me.DefaultChargeAccount.column(2) = sql_po_approved(0)
Then
MsgBox "made it to the if - they are the same on general
tab"
ElseIf Forms![Purchase Orders]!zPurchaseOrderItems.Form!
ChargeAccountID.column(3) = sql_po_approved(0) Then
MsgBox "made it to the elseif - they are the same on the
items tab"
Else
MsgBox "made it to the else - neither are the same"
End If

Thanks...John
 
Hello.  I have a mainform (Purchase Orders) and a subform
(zPurchaseOrderItems).  I am using the code below to determine if the
items in the subform match the projectid of the default charge acct.
The msgboxes are used for when building the routine to see where it
goes.  The first msgbox does show the appropriate projectid.  But in
the ElseIf line I get the problem.  It seems that the ElseIf is not
being looked at.  Even if I hardcode the projectid into the line in
place of the sql_po_approved(0) it still skips over it.  Is the
referencing of the subform correct?  Is this the way to go about
getting the info?

          Dim sql_po_approved As ADODB.Recordset
          Dim sql_po As String
          Set conn = New ADODB.Connection
          conn.Open "Driver={SQL Server};Server=test-
mxsql-02;Database=MTXMain;User ID=sa;Password=h0rn3t;" 'need to change
the server back to MXSQL before production
          sql_po = "SELECT ProjectID FROM ChargeAccounts WHERE ID =
dbo.POGetChargeAccountID(" & PONumber & ")"
          Set sql_po_approved = New ADODB.Recordset
          sql_po_approved.Open sql_po, conn, adOpenKeyset,
adLockReadOnly

          MsgBox sql_po_approved(0)

          If Me.DefaultChargeAccount.column(2) = sql_po_approved(0)
Then
            MsgBox "made it to the if - they are the same on general
tab"
          ElseIf Forms![Purchase Orders]!zPurchaseOrderItems.Form!
ChargeAccountID.column(3) = sql_po_approved(0) Then
            MsgBox "made it to the elseif - they are the sameon the
items tab"
          Else
            MsgBox "made it to the else - neither are the same"
          End If

Thanks...John

Never mind responsding to this post. I have figured out the
problem. Thank you for reading it.
John
 
John said:
Hello. I have a mainform (Purchase Orders) and a subform
(zPurchaseOrderItems). I am using the code below to determine if the
items in the subform match the projectid of the default charge acct.
The msgboxes are used for when building the routine to see where it
goes. The first msgbox does show the appropriate projectid. But in
the ElseIf line I get the problem. It seems that the ElseIf is not
being looked at. Even if I hardcode the projectid into the line in
place of the sql_po_approved(0) it still skips over it. Is the
referencing of the subform correct? Is this the way to go about
getting the info?

I'm not clear on what you are saying. If you "hardcode the projectid "
and it is equal to Me.DefaultChargeAccount.column(2) then you are done
and everything else gets skipped.
If not equal then the elseif statement is evaluated, etc.

Which is it?

As I said he first time I responded to one of your question, it seems that
properly related tables woulod remove a ton of code.
"If Me.DefaultChargeAccount.column(2) = sql_po_approved(0)" should be
handled by a relationship with no need to open a query.
Conditional formatting could then colorcode any wrong entries.

Dim sql_po_approved As ADODB.Recordset
Dim sql_po As String
Set conn = New ADODB.Connection
conn.Open "Driver={SQL Server};Server=test-
mxsql-02;Database=MTXMain;User ID=sa;Password=h0rn3t;" 'need to change
the server back to MXSQL before production
sql_po = "SELECT ProjectID FROM ChargeAccounts WHERE ID =
dbo.POGetChargeAccountID(" & PONumber & ")"
Set sql_po_approved = New ADODB.Recordset
sql_po_approved.Open sql_po, conn, adOpenKeyset,
adLockReadOnly

MsgBox sql_po_approved(0)

If Me.DefaultChargeAccount.column(2) = sql_po_approved(0)
Then
MsgBox "made it to the if - they are the same on general
tab"
ElseIf Forms![Purchase Orders]!zPurchaseOrderItems.Form!
ChargeAccountID.column(3) = sql_po_approved(0) Then
MsgBox "made it to the elseif - they are the same on the
items tab"
Else
MsgBox "made it to the else - neither are the same"
End If

Thanks...John
 
Back
Top