Error while entrying new value from combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, i get a error message while trying to add a new record through the not in list value, the error is "you cant fix a value to this object", and then a message about wrong data value i exppression. im using the following code in the text.box:

Private Sub Organisasjonsnummer_NotInList(NewData As String, Response As Integer)
Dim strsql As String, x As Integer
Dim FindCriteria As String
x = MsgBox("Dette selskapet er ikke registrert tidligere, vil du registrere selskapet? Det er nødvendig for å kunne fortsette registreringen!", vbYesNo)
If x = vbYes Then
strsql = "Insert Into Selskap ([organisasjonsnummer]) values ('" & NewData & "')"
'MsgBox strsql
CurrentDb.Execute strsql, dbFailOnError

FindCriteria = Me!Organisasjonsnummer.Text

DoCmd.OpenForm "Selskap", , , , , , FindCriteria

Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub

and as open form in the form i wish to add the value (so the form opens with the value adden in the text box:
Option Compare Database
Option Explicit
Dim Orgnr As String

Private Sub Form_Load()
Me.RecordsetClone.FindFirst "[organisasjonsnummer] = '" & Organisasjonsnummer & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark

End Sub


Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_Form_Open

Organisasjonsnummer = Nz(Me.OpenArgs)

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Error$
Resume Exit_Form_Open

End Sub

Is there any good sugestions to how to solve this problem. The field organisasjonsnummer is a text field in all tables involved.

Thanks..
 
Erik_norway said:
Hi, i get a error message while trying to add a new record through the not in list value, the error is "you cant fix a value to this object", and then a message about wrong data value i exppression. im using the following code in the text.box:

Private Sub Organisasjonsnummer_NotInList(NewData As String, Response As Integer)
Dim strsql As String, x As Integer
Dim FindCriteria As String
x = MsgBox("Dette selskapet er ikke registrert tidligere, vil du registrere selskapet? Det er nødvendig for å kunne fortsette registreringen!", vbYesNo)
If x = vbYes Then
strsql = "Insert Into Selskap ([organisasjonsnummer]) values ('" & NewData & "')"
'MsgBox strsql
CurrentDb.Execute strsql, dbFailOnError

FindCriteria = Me!Organisasjonsnummer.Text

DoCmd.OpenForm "Selskap", , , , , , FindCriteria

Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub

and as open form in the form i wish to add the value (so the form opens with the value adden in the text box:
Option Compare Database
Option Explicit
Dim Orgnr As String

Private Sub Form_Load()
Me.RecordsetClone.FindFirst "[organisasjonsnummer] = '" & Organisasjonsnummer & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark

End Sub


Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_Form_Open

Organisasjonsnummer = Nz(Me.OpenArgs)

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Error$
Resume Exit_Form_Open

End Sub

Is there any good sugestions to how to solve this problem. The field organisasjonsnummer is a text field in all tables involved.


It looks like you have a text box on the form that is also
named Organisasjonsnummer. If so, then you can't assign a
value to it in the Open event because it's too soon.

Try doing it all in the Load event:
Me.RecordsetClone.FindFirst _
"[organisasjonsnummer] = '" & Nz(Me.OpenArgs) & "'"

On the other hand, maybe you didn't mean to assign OpenArgs
to a text box and the problem is that you really meant to
assign OpenArgs to the module level variable Orgnr?
 
Great.. that did the trick!..

but, never a solution without a new problem. I have a simular field (text) that i now use the same code on. But when i trye to close that form i get a error. The error is that the value cant be addes because that would cause duplicates. I understand that what happens (proberly) is that the form in some way tryes to add a new record when closing. When the other form already added the same value i see the problem. BUT with the field organisasjonsnummer this works great.. I cant find any differences between these two! Anyone got some idea on what to look for?

AND: wish to say thanks to all here for great help - hope that i can contribute soon!
 
Back
Top