VBA Help with Code - link with AutoNumber?

  • Thread starter Thread starter TAMAJAMA
  • Start date Start date
T

TAMAJAMA

Guest
I have run into a problem with sending code to a new form. This code shown below was previously working, however it was sending a text "query" to the form named "COC Form", now I need it to send the AutoNumber (which is also the Primary Key). Is there any reason why the code would not work with AutoNumbers set as the Primary key?

Private Sub Command102_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "COC Form"

stLinkCriteria = "[IDNUMBER]=" & "'" & Me![IDNUMBER] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Exit_Command102_Click:
Exit Sub

Err_Command102_Click:
MsgBox Err.Description
Resume Exit_Command102_Click

End Sub

THANKS IN ADVANCE FOR ANY HELP!!
TamaJama
 
Has the current record from the open form been saved prior to trying to pass the autonumber to the new form. If not then save it before opening the new form.

doCmd.RunCommand acCmdSaveRecord
 
Could also be the problem you're encountering is caused by the single quotes in the criteria you're sending. When comparing numbers instead of text you don't use them. This may do it.

stLinkCriteria = "[IDNUMBER]=" & Me![IDNUMBER]

Good Luck
~Abby

[This message has been edited by Abby N (edited 08-22-2001).]
 
Pat, Thanks for the reply!
Yes the record has already been saved to the database. The code was tested on existing records in the database (I see your logic, though).

Do you see anything else wrong with the code that would keep it from compiling? The weird thing, is that it worked when it was passing a text field, however, when I changed it to IDNUMBER (which is the autonumber and primary key and there are no duplicates), I get the error. Is there any qualifiers that have to be included when you are sending numbers?

I am at a total loss with it.
Thanks again!
TamaJama
 
Abby N!
Thanks so much!
We had posted our replies at the same time! I tried your advice and it worked perfectly. It makes sense, too! I think I was just to into it and couldn't step back and think logically
smile.gif


Thanks again Abby!
Tamara
 

Users who are viewing this thread

Back
Top Bottom