Why Isn't This Code Working?

Jun 6, 2007

Hello, all! Can you please look at the following code and tell me why it throws a compile error of user type not defined. I'm trying to use this code to automatically pull in the previous room # and associated data into the next record, so that I don't have to enter the data every time, as sometimes there are fifty entries with the same room # and associated data. Can you tell me what it's wrong with it? Thank you!!

VB Code: Original - VB Code Private Sub Form_Current()Dim s As StringDim db As New ADODB.ConnectionDim rs As New ADODB.RecordsetSet db = CurrentProject.Connections = "SELECT Last(Room #) AS Room # FROM [tblFF&EBudget] WHERE Budget Line=(select max(Budget line) from [tblFF&EBudget])"Set rs = New ADODB.Recordsetrs.Open s, db, adOpenDynamic, adLockOptimistic'add to the tableWith rsMe![Room #] = .Fields("Room #")End WithSet rs = NothingSet db = NothingEnd Sub Private Sub Form_Current() Dim s As StringDim db As New ADODB.ConnectionDim rs As New ADODB.RecordsetSet db = CurrentProject.Connection  s = "SELECT Last(Room #) AS Room # FROM [tblFF&EBudget] WHERE Budget Line=(select max(Budget line) from [tblFF&EBudget])" Set rs = New ADODB.Recordsetrs.Open s, db, adOpenDynamic, adLockOptimistic'add to the table With rsMe![Room #] = .Fields("Room #")End WithSet rs = NothingSet db = Nothing End Sub
Thanks!

KellyJo

View Replies


ADVERTISEMENT

Form Code Not Working

Aug 1, 2005

Maybe this should be posted under VBA.... not sure. Havent seen answer that works yet.
Its a form with an option group "PickWO" When you pick an option, different fieilds become visible-non visible. I created a field "PickWOvalue" to store the option value "1" or "2". That part works fine.(visible) The problem is when you reopen the form to view the records the option box value does not show or change the fields visible properties. And the on open cuauses an error. Anyone see the problem?




Private Sub Form_Open(Cancel As Integer)
Me.PickWOvalue.Value = Me.PickWO.Value
End Sub
`````````````````````````````````````
Private Sub PickWO_AfterUpdate()

Call NotVisible

Select Case Me.PickWO

Case Is = 1
Me.ReInspectionDate.Visible = True
Me.Price.Visible = False
Me.WOPreview.Visible = True
Me.PrtWO.Visible = True
Me.WBMInvoice_.Visible = False

Case Is = 2
Me.ReInspectionDate.Visible = False
Me.Price.Visible = True
Me.cmdPreTag.Visible = True
Me.cmdPrtTag.Visible = True
Me.WBMInvoice_.Visible = True


End Select

End Sub

View 6 Replies View Related

VB SQL Not Working In Code, But Does In Query

Aug 18, 2004

I have an access database that links to a SQL server.
My problem is when I made a copy of the Access database,
made changes to one sub report and mapped to test tables and now I have VB code that
runs the overall report where the SQL gets jammed on the join, (which I noticed through debugging)
but when I take the same SQL and run it in the Query view - the SQL works.

has anyone seen anything like this before?

View 6 Replies View Related

Code Not Working Properly..urgent Pls.

Apr 17, 2006

Hi All,

I have Header form and subform subform in it with following fields

Subform fields are :

1. MQE_No : (Text field as it will be like MG-120, MG230), Duplicate OK)
2. RPO_No : (Number field – Double, Duplicate OK ) The are project no.
3. ForemanNo (Number field – Long Int – Duplicate OK)

Header form fields are ;

1.ForemanNo – Long Int – No Duplicate
2.Other fields…

The subform field have ForemanNo One-To-many relationship with Header form.

Following project MG-411 need to enter (assign) to foreman no. 641

Actual data to store in subform

MG-411 (MQE_NO)
5421654 (RPO_NO)
641 (FOREMANNO)

I started to enter data into subform selecting the ForemanNo at header so records to enter in specific foremans account. Everything is fine here.

What I need is:

I would like to select / add another Foreman into the header and start entering same above data for another Foreman. Bcz sometimes we need to do like this in case previous Foreman may go on to a week vacation. We can not stop project for a week. So need to assign project to other foreman.

When selected the Project (MG-411) thru a combo to assign it with other foreman, it should give a short msg to user that this project has already been assigned to “XYZ” forman. Need to assign again “ (Y/N box )

If Y then data entered otherwise cancelled.

To achieve this, I did the following but only 50% success. (Used Cmbo CboRPO2 select MQE_NO). Tried to satisfy both condition but no use.

Private Sub CboRPO_AfterUpdate()
If DCount("*", "T_RPO_Footer", "RPO_No = " & RPO_No) > 0 And DCount("*", "T_RPO_Footer", "ENO = " & ENO) Then
MsgBox "RPO ALREADY ASSIGNED TO SOMEONE / FOREMAN", vbOKCancel, "WARNING!!!"
Me.Undo
Exit Sub
Else

Dim Msg, STYLE, TITLE, HELP, CTXT, Response, MYSTRING
If DCount("*", "T_RPO_Footer", "RPO_No = " & RPO_No) > 0 And DCount("*", "T_RPO_Footer", "ENO <> " & ENO) Then
Msg = "RPO ALREADY EXIST WITH OTHERFOREMAN, ASSIGN AGAIN TO ANOTHER ?"
STYLE = vbYesNo + vbInformation + vbDefaultButton2
TITLE = "!! ATTENTION !!"
HELP = "TEST FILE"
CTXT = 1000
Response = MsgBox(Msg, STYLE, TITLE, HELP, CTXT)

If Response = vbYes Then

Me.MQE_NO = Me.CboRPO.Column(0)
Me.RPO_No = Me.CboRPO.Column(1)
Me.WORKSHEET_NO = Me.CboRPO.Column(2)
Me.WORKORDER_NO = Me.CboRPO.Column(3)
Me.WORK_DESC = Me.CboRPO.Column(4)
Me.PL = Me.CboRPO.Column(5)
Me.PipeLineKM = Me.CboRPO.Column(6)
Me.DiaMeter = Me.CboRPO.Column(7)
Me.PipeLength = Me.CboRPO.Column(8)
Me.PipeLineArea = Me.CboRPO.Column(9)
Me.P = Me.CboRPO.Column(10)
Me.RPO_AMOUNT = Me.CboRPO.Column(12)
Me.INV_AMOUNT = Me.CboRPO.Column(13)
Me.Status = "WIP"
Me.StatusID = 2
Me.CboStatus.SetFocus
Else
Me.Undo
Exit Sub
End If

Else
Me.MQE_NO = Me.CboRPO.Column(0)
Me.RPO_No = Me.CboRPO.Column(1)
Me.WORKSHEET_NO = Me.CboRPO.Column(2)
Me.WORKORDER_NO = Me.CboRPO.Column(3)
Me.WORK_DESC = Me.CboRPO.Column(4)
Me.PL = Me.CboRPO.Column(5)
Me.PipeLineKM = Me.CboRPO.Column(6)
Me.DiaMeter = Me.CboRPO.Column(7)
Me.PipeLength = Me.CboRPO.Column(8)
Me.PipeLineArea = Me.CboRPO.Column(9)
Me.P = Me.CboRPO.Column(10)
Me.RPO_AMOUNT = Me.CboRPO.Column(12)
Me.INV_AMOUNT = Me.CboRPO.Column(13)
Me.Status = "WIP"
Me.StatusID = 2
Me.CboStatus.SetFocus
End If
End If
End Sub


I tried with following code also

'Dim cdn As String
'cdn = "[MQE_NO] = '" & Nz(CboRPO, "") & "'"
'cdn = cdn & " And ENO = " & ENO

'If DCount("*", "T_RPO_Footer", cdn) > 0 Then
'MsgBox "THIS RPO ALREADY ASSIGNED TO THIS FOREMAN", vbOKOnly, "WARNING!!!"
'Me.Undo
'Exit Sub
'Else
‘do something
‘End if

Can somebody help it please.

With kind regards,
Ashfaque

View 1 Replies View Related

Module Code Stops Working

Nov 17, 2006

just wondering why randomly certain modules in the form code stop working..

when you accidentally press return.. or do something in the wrong order.. or apply one rule to one control.. and then another control rule stops working..

so you have to delete the code.. right click on the control's event.. and re-insert the code into the event section.. and then it works..

why?

View 4 Replies View Related

Calculate A Persons Age Code Not Working.

Oct 20, 2006

Hi all I have another code Problem, Can someone help me with this.
I have two fields
One called cust_birthday ( date field )
And one called cust_age ( text field )
The code below I put in a module name age function.

The Problem, is I get no return from this code.

What is wrong with this code ????

Option Compare Database

Public Function Age(cust_birthday As Date, Optional cust_age As Variant) As Integer
Dim dteBase As Date, intCurrent As Date, intEstAge As Integer
If IsMissing(SpecDate) Then
dteBase = Date
Else
dteBase = SpecDate
End If
cust_age = DateDiff("yyyy", dteDOB, dteBase)
cust_age = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
Age = cust_birthday + (dteBase < cust_age)
End Function

John527

View 6 Replies View Related

Code Ot Working, Brings Out Null Value

Dec 8, 2006

Can anyone see why the sql code below is not working, it works up unitl

StrSQ4 = DLookup("[D Status]", "tbl_Delupdate", "[Cylinder Barcode Label]='" & Stringy1 & "'")

But when i try to get the latest date for that Cylinder Barcode as shown below it does not bring out a value

StrSQ4 = DLookup("[D Status]", "tbl_Delupdate", "[Cylinder Barcode Label]='" & Stringy1 & "'AND [Date of D Status]=#" _
& DMax("[Date of D Status]", "tbl_Delupdate", "[Cylinder Barcode Label] = '" & Stringy1 & "'") & "#")

View 6 Replies View Related

General :: Code To Create Several Rows In Table Not Working

Jun 4, 2014

I have an issue with a code that I have in a form which adds rows in a table as many times as categories chosen from a list. However, the code is not working correctly: it adds the information and creates a row with a category in blank, in addition to the rest of the rows with one of the chosen categories. I would like for this not to happen, to add only as many rows as the categories chosen.

My code is the following:

Private Sub cmdUpdate_Click()
Dim valSelect As Variant, MyDB As DAO.Database, MyRS As DAO.Recordset
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("Tasks", dbOpenDynaset)
MyRS.MoveFirst

[Code] .....

View 6 Replies View Related

Modules & VBA :: Modify Working Code - Export Query And Update Worksheets In Excel Template

Mar 12, 2014

What I want to do instead is open an existing .XLSM wokrbook delete or update the 7 sheets it creates and replace them with the new query results from access.

I love this code below because it works really well but now I have a new requirement. I have a workbook that has a "dashboard" sheet that looks at the sheets from acccess and summerizes the data. So, I'd like Access to open that "template" excel workbook and delete the old sheets and put in the new ones..The required sheets to keep are called "Metrics", "Validation" and "Mara"

What I was trying to do for the past few hours was another work around which was to have Access run this code, then excel run some code to import the "dashboard" formulas but I can't get it to copy to another workbook because it links to the OLD workbook..Here is the working code that needs modding:

Code:

Option Compare Database
Public Function ExportAdvanced()
Dim strWorksheet As String
Dim strWorkSheetPath As String
Dim appExcel As Excel.Application
Dim sht As Excel.Worksheet
Dim wkb As Excel.Workbook
Dim Rng As Excel.Range
Dim strTable As String
Dim strRange As String
Dim strSaveName As String
Dim strPrompt As String
Dim strTitle As String
Dim strDefault As String

[code]...

View 3 Replies View Related

None Working "simple Code" On Close Event?

May 16, 2006

I have witten a code in the close event of a "Primary" form that would update a Combo boxe on a "secondary" form only if the "secondary" form is open.
ie:

Private Sub Form_Close()
If Forms!frmEnquiry.Open Then
Forms!frmEnquiry!CboCustomer.Requery
Else
DoCmd.Close
End If
End Sub

This code keeps giving me an error, is anybody has got any idea why?
Thanks in advance.

View 7 Replies View Related

Program Working In Access 2007 Not Working In Access 2010 Due To Missing OCX File

Dec 27, 2014

I have a program that runs under access 2007 that I use at my work. We will soon be updating to MS office 2010 and the program will not work now because a calender file .ocx was removed from access 2010. Is there a way to get the 2007 .ocx file to work in access 2010?The program I am using is a relatively simple stand-alone and unsupported app that we use to request patient arrival and departure from various radiology tests inside a hospital. No reports are made from the app other than the number of patient transports for the day.

The app is placed on a common drive accessed from any pc in the hospital. No special permissions are required. But our app does use the calendar, time and date functions in access 2007. When I tried the app on a pc with access 2010, it basically says it (access) cannot open the app because a .ocx file is not present.Is there a way to make the access 2010 calendar file work in access 2007?

View 1 Replies View Related

Duplicate Record Command Button Not Working For One Form But Is Working For Other Form

Jan 15, 2015

I have an Access 2010 database with two tables and two forms. The tables are Organizations and People. Similarly, the forms are Organizations Entry Form and PeopleEntryForm. The People are linked to the Organizations table. Several people can be linked to the same organization.On my Organizations EntryForm, I created a command button to duplicate a record using the wizard. It works fine.

I did exactly the same thing on the PeopleEntryForm, but instead of copying the record, it creates a new blank record. I don't get any error messages. Is my problem due to the fact that the People table is linked to the Organizations table?

View 13 Replies View Related

Please Review This Code, (simple Code) New With Codes

Feb 16, 2006

Works great, but when I hit the number "3", (3 times in row) it will let me into the form. I want it to not let me in IF I don't know the password.

Where did I go wrong?

Private Sub Form_Load()
Dim pw As Variant

If InputBox("What is the password?", "Password") = "1" Then
Else
MsgBox "Invalid Password", vbCritical, "Sorry Charlie"
DoCmd.Close
If InputBox("What is the password?", "Password") = "2" Then
Else
MsgBox "Invalid Password", vbCritical, "Sorry Charlie"
DoCmd.Close
End If
End If


End Sub

View 14 Replies View Related

Using Code To Unprotect And Protect Viewing Code

Jan 14, 2007

I protect my code from people being able to read it by setting a password on the code from Tools > Properties, selecting the Protection tab and entering a password, and clicking "Lock Project"

Is there a way to write code that will remove that Lock Project check and check it back on?

I've looked through the Application.SetOption command and it doesn't seem to be one of the choices. It would be very helpful if someone knew how to do this.

Thanks

SHADOW

View 6 Replies View Related

Working Out How Old Someone Is

May 10, 2005

Hi all,

I'm making a simple query to tell me how old a list of members are in a database.

I figure as I have their birthday, armed with todays date access should be able to tell me (in years only) how old they are.

Any help is appreciated

View 14 Replies View Related

MDE Not Working?

Jul 19, 2005

Hi,

I have 2 computers (computer 1 with Office XP and computer 2 with Office XP SP1). An MDE file created from an MDB file on computer 1 will not work on computer 2 (run time error), but an MDE file created on computer 2 also does not work on computer 1 (error message was "database corrupted").

Does anyone know why and what I can do to make the MDE work on both machines?

View 6 Replies View Related

MDE Not Working

Jul 21, 2006

Hi. I have got a small database, I have split it into front and back end. I then try to make an MDE out of the front end and after going to tools>db utilities>make MDE file, i got the save as box open up and i pressd save to my desktop,the box disappears and the screen is just blank(like there is no database file has been open,at the bottom of Access it says Make MDE/ADE.
And it just crashes.. it doesnt come up with any errors.
If anyone has any information pleeeeeaaaseee help.......

View 8 Replies View Related

Cbo Not Working Well

Aug 2, 2005

My Combo Box works and displays new entries in text boxes in my form. The selection appears in every record. I would like the selection to be stored only in the displayed record and not for each and every record. Any ideas?

My combo box works on an existing query( Qry1). I would like the data from my query (Qry1) to be displayed in the record (in Form1) which I am viewing. When I go onto a new record (IN Form1) I would like to make a new selection from my query (Qry1) and then store these details in the new record in Form1.

I am a little frustrated - please help.

View 3 Replies View Related

Sum() Not Working

Sep 20, 2006

This seems so simple, but, being a novice, I'm scratching my head.

I'm using an unbound text box in the form footer to sum the value of a column in the form ( =Sum([LineTotal]) ). [LineTotal] evaluates correctly, yet the sum is always #ERROR. Is there something I am missing, or am I correct in thinking that this should work?

Thanks to anyone who can shed some light.

-Don

View 7 Replies View Related

Why Is This Not Working ?

Nov 8, 2004

I open a form that is bound to a linked SQL table. On that form a have a list box that shows a series of records based on a query. The listbox DOES contain the PK field "Record_date" in its query.

I am expecting that if I click on a given record in the list box the form would change to that matching record. What am I doing wrong ?

List box code:

Private Sub List212_AfterUpdate()

' Find the record that matches the control.
Dim rst As Object
Set rst = Me.Recordset.Clone
rst.FindFirst "[Record_date] = #" & Format(Me![List212], "mm/dd/yyyy") & "#"
If Not rst.EOF Then Me.Bookmark = rst.Bookmark

End Sub

If I change the form record and click the list box, its always takes me back to the 1st record - not the matching record selected in the form.

Help ?

View 3 Replies View Related

Why Is This Not Working??

May 8, 2005

Hy,i've got three tables:
products:
product_id,product_name
months:
month_id,name_of_month
calculations:
calculations_id,month_id,amount

Also have this query:

SELECT DISTINCTROW products.product_name, Sum(calculations.amount) AS [Sum Of amount]
FROM products INNER JOIN calculations ON products.product_id=calculations.product_id
WHERE calculations.month_id in (forms!frmMyForm!txtMyTextbox.value)
GROUP BY products.product_name;

My problem lies in this part of query :
WHERE calculations.month_id in (forms!frmMyForm!txtMyTextbox.value).

I've got problem when i want to get values from my textbox on my form.
If i instead (forms!frmMyForm!txtMyTextbox.value) put (1,2) my query works fine,but when i wanna get this same values from textbox on my form it returns me an error.
I have also noticed one more thing:If i put in my textbox just value 1 it works fine,but if i use more values separeted by comma instead of result it returns me an error.
Why is this,and how to avoide this problem?
Thanks!

View 8 Replies View Related

Why Isn't This Working

Jul 29, 2005

Private Sub propertypass_Click()

If [Forms]![UpdatedFullInventory]![PAM_ID] = [Tables]![UpdatedPropPassInventory]![PAM_ID] Then
MsgBox "A property pass for PAM ID " & PAM_ID & " has already been created. Please search the property pass database for more information!", vbOKOnly, "Error!"
End If

My debug message says

Microsoft can not find the field 'l' referred to in your expression.

View 1 Replies View Related

Breakpoints Not Working

May 13, 2005

Hello,

For osme reason this MS Access database I'm working on will not let me debug it. First off, even if I mistype a variable name it is not breaking and giving me an error message. I checked and I do have 'Option Explicit' set as well as "Error Trapping - Break on All Errors" in the Tools - Options - General.

Also, when I set a breakpoint in my code, it doesn't work either.

Any ideas as to what is going on??

Thanks,

Brian

View 1 Replies View Related

Database Not Working?

Jun 23, 2005

Our database is 1.6gb in size.
It has stopped working, is there a way to delete old records?
We are told it will crash the computer, because access needs the same space as the data its self.
Any ideas?
Thank you for your time in reading this post

View 2 Replies View Related

MsgBox Not Working!

Jun 29, 2005

Can anyone tell me whats wrong with this code, its not working for me!!


If ((txtpassword = "") Or (combusername = "")) Then

MsgBox "Please Enter A Valid Access", vbOKOnly, "Error"

End If

View 4 Replies View Related

CancelEvent Not Working

Aug 5, 2005

Hi,
I've the following code but the cancel doesn't seem to be working, when upon click cancel, it should still remain on the form but it closed the form. Can someone please advise.

Dim strMsg As String
Dim strMsg2 As String
Dim strTitle As String
Dim strTitle2 As String
Dim intResponse As Integer

strMsg = "Do you wish to save changes?"
strMsg2 = "The changes you made were not saved."
strTitle = "Save Entry"
strTitle2 = "Entry Canceled"

If Me.Dirty Then
intResponse = MsgBox(strMsg, vbYesNoCancel, strTitle)
If intResponse = vbNo Then
Me.Undo
MsgBox strMsg2, vbOKOnly, strTitle2
ElseIf intResponse = vbCancel Then
DoCmd.CancelEvent
Me.SetFocus
End If
End If

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved