Compile error: Variables not defined

klwu

Brainy!!
Local time
Today, 21:55
Joined
Sep 13, 2004
Messages
47
Hi, I have some problems with my codes here. The system keeps saying that my variables not defined. How do I solve this problem? Thanks

Code:
Private Sub cmdCreateNew_Click()
On Error GoTo Err_cmdCreateNew_Click
'1.Check if cmbCompanyID is selected
'2.Generate a unique numer for this Company ID
'3.Insert a row in M_Ip table
'4.Go to IPAddress form

Dim sSql As String, refIx As Long, dbs As Database

'task 1 begins here--------
If IsNull(cmbCompanyID) Or cmbCompanyID = "" Then
    MsgBox "Please select the Company ID"
    GoTo Exit_cmdCreateNew_Click
End If

'task 2 begins here--------
refIx = NextVal(cmbCompanyID)
        
   
'task 3 begins here-------
sSql = "INSERT INTO M_Ip (RefNo, CompanyID) VALUES" & _
       "(" & refIx & ", '" & [B]txtCompanyID [/B] & "');" [COLOR=Red]<- Error here[/COLOR]

'task 4 begins here------
    DoCmd.OpenForm "IPAddress", acNormal, , "RefNo =" & refIx
    DoCmd.SetWarnings True
    cmbCompanyID = ""
    
'MsgBox sSql
    DoCmd.SetWarnings False
    DoCmd.RunSQL sSql

   
Exit_cmdCreateNew_Click:
    Exit Sub

Err_cmdCreateNew_Click:
    MsgBox Err.Description
    Resume Exit_cmdCreateNew_Click
    
End Sub
 
I'm assuming that you think that txtCompanyID is the name of a field on the current form. You can verify that this is the problem by using the "Me." qualifier because it provides intellisense. So ---

Me.txtCompanyID

is better technique. As soon as you type "Me.", you should see a list of properties and methods for the form. One of the items in the list should be - txtCompanyID. If the name doesn't appear in the list, that means that the actual control/field name is different.
 
Sorry, I think I didn't actually explain my problem.

I have 2 forms: AddIP and IPAddress. I have a combo box in
AddIP form, I want to do like when the user selects a Company ID in this
form and after the button 'Create New' is clicked, the IPAddress form will
appear with a new Ref. No. (from T_Counter table) and the Company ID field is populated with the ID (from R_CompanyID table). The code I wrote is meant for the "Create New" button.

Could someone advise me on this?
 
klwu,

When I took the " <- Error here" away from the end of the line, there is
no compile error.

It compiles fine in A2000.

Wayne
 

Users who are viewing this thread

Back
Top Bottom