need help setting a variable

Jim W

Registered User.
Local time
Today, 10:54
Joined
Feb 4, 2003
Messages
198
I have a form where users enter a part number the format is 1111-11111
What happens is they enter a number and if it is not on the list a message box opens giving the user an option to enter a new part to the list or allowing them to change the number and continue. If they select Yes to add a new part number a new form opens for them to a new part number. What I'm trying to do is in the ON NOT IN LIST is have code that sets this number as a variable and then on the new form I can get the variable so the user does not have to re-enter the number again. but when setting the variable I get Null errors. and when I stop the code and cheak the MyVariable = 0
I have this line in a module Public MyVariable As Integercreate

any ideas

Jim
 
This is the code in the Not in list property setting. The table has the part number as Text so I changed the module to Public MyVariable As String When the code runs I get the not on list error once I click yes I get an invald use of null and the code stops with the line MyVariable = Me.[Part Number] highlighted. If is move the mouse over the MyVariable it shows "" for a value
WHY?

Thanks for looking
Jim

Dim StdResponse As Integer
StdResponse = MsgBox("Would you like to add this Part Number to the Look Up Table? NOTE: You will not be able to claim usage of this part unless it is in the Parts Lookup table", 52, "This " & "Part Number is not in the Parts Look Up Table")
If StdResponse = 6 Then 'Yes
MyVariable = Me.[Part Number]
DoCmd.Echo False
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.OpenForm "Frm-Adding PartsA"
DoCmd.Maximize
DoCmd.Echo True
DoCmd.GoToRecord acForm, "Frm-Adding PartsA", acNewRec
DoCmd.Close acForm, "Frm-Parts UsedA"
Response = DATA_ERRCONTINUE
Else 'No
Response = DATA_ERRCONTINUE
Exit Sub
End If
 
Use something like this

Private Sub Payee_NotInList(NewData As String, Response As Integer)
Dim Msg, Style, Title, MyString

Beep
Msg = "You have entered a Payee that has not been recorded do you wish to enter this Payee or remove the entry. Select yes to add supplier, No to cancel entry. "
Style = vbYesNo + vbExclamation + vbDefaultButton1
Title = "No supplier details listed"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
DoCmd.RunCommand acCmdUndo
DoCmd.OpenForm "PayeesFrm", acNormal, , , acAdd, acDialog, NewData

Response = acDataErrAdded
End If
End Sub
 
Rich, if I use the code you provided I still have the same problem. When the form opens for adding the new number I would like the number filled in from the other form. I'm trying to make it a little simpler for the users.

Jim
 
When the form opens for adding the new number I would like the number filled in from the other form.

You can always try to do a cross-form reference. You know the name of the form and the name of the control that holds the number. In the pop-up form's OnOpen event, you could look at the list of open forms in the database's Forms collection. If your original form is open, just reference it.

NOTE: If the add-payee form could also be used directly, the test for the other form being open is necessary to transfer data but it should not be fatal if the form was directly opened.

Another possibility is that if a pop-up is opened by another form, the form that did the OpenForm is the "parent" - so in the pop-up, there would be the ability to do something like Me.Parent.Name to see if this original form is the one you expected.

I know there are topics in the help files regarding accessing controls from other forms. Give them a look.
 
Jim W said:
Rich, if I use the code you provided I still have the same problem. When the form opens for adding the new number I would like the number filled in from the other form. I'm trying to make it a little simpler for the users.

Jim
The code as posted should add the Record to your second form. Did you copy it as posted and just change the relevant parts?
 

Users who are viewing this thread

Back
Top Bottom