×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Having Problem w/ Code

Having Problem w/ Code

Having Problem w/ Code

(OP)
I used this code:


    Dim SQL1 As String, Rs As Recordset, Db As Database, Ctl As Control
    Set Db = CurrentDb()
    If IsNull(Me.YourFieldName) Or Me.YourFieldName = "" Then
        MsgBox CurrentUser() & ", please add an appropriate drawing number.", vbInformation, "Drawing number required..."
        Set Ctl = Me.YourFieldName
        Response = acDataErrContinue
        Ctl.Undo
        Ctl.SetFocus
    Else
        SQL1 = "SELECT YourTableName.* FROM YourTableName"   'check for dup names
        Set Rs = Db.OpenRecordset(SQL1, dbOpenDynaset)
        If Rs.RecordCount = 0 Then
            Rs.Close
            GoTo NewDrawing
        End If
        Rs.MoveFirst
        Do Until Rs.EOF
            If Rs!YourDrawingField = Me.YourFieldName Then
                Rs.Close
                MsgBox "There is already a drawing with number ''" & Me.YourFieldName & "''. Please chose an alternate.", vbInformation, "Drawing Number Exists!"
                Me.YourFieldName = Empty
                Exit Sub
            End If
            Rs.MoveNext
        Loop
        Rs.Close

NewDrawing:
        SQL1 = "SELECT YourTableName.* FROM YourTableName"
        Set Rs = Db.OpenRecordset(SQL1, dbOpenDynaset, dbAppendOnly)
        Rs.addnew
        Rs!YourDrawingField = Me.YourFieldName
        Rs.Update
        Rs.Close
    End If

I'm Having a heck of a time with what table names are to go where I'm preventing duplicate in the Electrical table
What am I to put in the : YourDrawingField   ?

RE: Having Problem w/ Code

Hi Joel, kind of missed you over here...sorry...

YourDrawingField is the name of the field in your table: should be realistically the same name as YourFieldName.

Please don't forget: if either is named like:

Drawing Number  you must type them in like  Drawing_Number  or Access will get all confused. If it is one "word" DrawingNumber , you have no issues. Keep at it. I'm watching now...!    :)

Gord
ghubbell@total.net

RE: Having Problem w/ Code

(OP)
Get an error on (me.drawlog)  


If IsNull(Me.YourFieldName) Or Me.YourFieldName = "" Then

Member or data method not found!


what do you thinks the error here

J

RE: Having Problem w/ Code

(OP)
Scratch that last one

i get an error on 'response'
 Response = acDataErrContinue

RE: Having Problem w/ Code

Joel, paste your code as you've built it in here... Let's have a look...

Gord
ghubbell@total.net

RE: Having Problem w/ Code

(OP)
Private Sub Drawing_Number_AfterUpdate()
    
    Dim SQL1 As String, Rs As Recordset, Db As Database, Ctl As Control
    Set Db = CurrentDb()
    If IsNull(Me.Drawing_Number) Or Me.Drawing_Number = "" Then
        MsgBox CurrentUser() & ", please add an appropriate drawing number.", vbInformation, "Drawing number required..."
        Set Ctl = Me.Drawing_Number
        Response = acDataErrContinue
        Ctl.Undo
        Ctl.SetFocus
    Else
        SQL1 = "SELECT drawlog.* FROM drawlog"   'check for dup names
        Set Rs = Db.OpenRecordset(SQL1, dbOpenDynaset)
        If Rs.RecordCount = 0 Then
            Rs.Close
            GoTo NewDrawing
        End If
        Rs.MoveFirst
        Do Until Rs.EOF
            If Rs!Drawing_Number = Me.Drawing_Number Then
                Rs.Close
                MsgBox "There is already a drawing with number ''" & Me.Drawing_Number & "''. Please chose an alternate.", vbInformation, "Drawing Number Exists!"
                Me.Drawing_Number = Empty
                Exit Sub
            End If
            Rs.MoveNext
        Loop
        Rs.Close

NewDrawing:
        SQL1 = "SELECT drawlog.* FROM drawlog"
        Set Rs = Db.OpenRecordset(SQL1, dbOpenDynaset, dbAppendOnly)
        Rs.AddNew
        Rs!Drawing_Number = Me.Drawing_Number
        Rs.Update
        Rs.Close
    End If

Here we go.
J

RE: Having Problem w/ Code

Ooops! we forgot to "Declare a variable" my fault I think so sorry. Bad Gord! Bad!


Dim SQL1 As String, Rs As Recordset, Db As Database, Ctl As Control,Response as integer

add that last bit and see how it goes...... :(    :)

Gord
ghubbell@total.net

RE: Having Problem w/ Code

(OP)
I tried the code up above and no such luck yet

any thoughts

J

RE: Having Problem w/ Code

Morning Joel, do me a favor if you'd like: Copy, Compact~(zip if you have it) and email me your Db or your problem area. I'll take a closer look at it here. My treat. I'll post my findings here too.  

Gord
ghubbell@total.net

RE: Having Problem w/ Code

(OP)
I just zipped it and sent it you shoul dget it in about 10 minutes

J

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close