How did i manage to break this?

Darrenc

Registered User.
Local time
Today, 19:40
Joined
Apr 30, 2004
Messages
62
I've somehow managed to break a tiny bit of code that was working fine, i've been racking my brains on what i could have done to break it.

My code is this

Code:
Private Sub cmdNewSupQuery_Click()
On Error GoTo Err_cmdNewSupQuery_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    
    DoCmd.OpenForm "frmSupplierQuery", , , "[SupCustomerID]=" & Me.CustomerID
    
    stDocName = "frmSupplierQuery"
    
    stLinkCriteria = "[SupCustomerID]=" & Me![CustomerID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdNewSupQuery_Click:
    'Exit Sub

Err_cmdNewSupQuery_Click:
    MsgBox Err.Description
    Resume Exit_cmdNewSupQuery_Click
    
End Sub

Before i had a couple of days off, this code was working fine, i would click the button and the SupCustomerID would automaticly filled in by the CustomerID field and then link together.

Now for some reason the SupCustomerID field is not being filled in.

Has anyone got any Idea's how i've managed to break this?
 
Last edited:
You might add a bit of coded as below to see if CustomerID is valid.



Private Sub cmdNewSupQuery_Click()
On Error GoTo Err_cmdNewSupQuery_Click

Dim stDocName As String
Dim stLinkCriteria As String

msgbox(Me![CustomerID]

DoCmd.OpenForm "frmSupplierQuery", , , "[SupCustomerID]=" & Me.CustomerID

stDocName = "frmSupplierQuery"


stLinkCriteria = "[SupCustomerID]=" & Me![CustomerID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdNewSupQuery_Click:
'Exit Sub

Err_cmdNewSupQuery_Click:
MsgBox Err.Description
Resume Exit_cmdNewSupQuery_Click

End Sub
 
Sorry but I missed a closing ")" on the end of the last message

Sam
 
Looks like you're trying to open the same form twice...

Try this:

Code:
Private Sub cmdNewSupQuery_Click()
On Error GoTo Err_cmdNewSupQuery_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    
'    DoCmd.OpenForm "frmSupplierQuery", , , "[SupCustomerID]=" & Me.CustomerID
    
    stDocName = "frmSupplierQuery"
    
    stLinkCriteria = "[SupCustomerID]=" & Me![CustomerID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdNewSupQuery_Click:
    'Exit Sub

Err_cmdNewSupQuery_Click:
    MsgBox Err.Description
    Resume Exit_cmdNewSupQuery_Click
    
End Sub
 
I also notice you are missing the "!" in your Me![CustomerID]
 
Thanks for the speedy replys.

CustomerID exsists and is returning the right value, its just not populating the other field.
I also notice you are missing the "!" in your Me![CustomerID]
Not sure where this is missing from :o

KenHigg
I'm probably wrong, my understanding is that it need to open up the other form so that it can populate the field, and then its opens the form again to link them together.
I'm sure there's probably a better way of doing it.
Anoying thing is, it was working fine, i just can't think what could have changed :(
 
Fixed it

I did some more searching and found Pat suggested another way of doing it.
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
        Me.txtUserloggedIn.Value = LoginName
        Me.SupCustomerID = Forms!frmCustomerReturn!CustomerID
End Sub
[\CODE] 

There's always more that one way to skin a cat!!
 

Users who are viewing this thread

Back
Top Bottom